JDBC连接MySQL和Oracle

JDBC连接MySQL和Oracle,第1张

1.Oracle连接语句://对应class12.jar

String driver="oracle.jdbc.driver.OracleDriver"

String url="jdbc:oracle:thin:@localhost:1521:test"

//...........:oci8:@localhost:1521:test

Connection con=null

try

{

Class.forName(driver)

con=DriverManager.getConnection(url,"scott","tiger")

}catch(ClassNotFoundException)

{ }catch(SQLException){}

2.SQL连接语句://对应jtds.jar

String driver="net.sourceforge.jtds.jdbc.Driver"

String url="jdbc:jtds:sqlserver://localhost:1433/test"

Connection con=null

try

{

Class.forName(driver)

con=DriverManager.getConnection(url,"sa","")

}catch(ClassNotFoundException)

{ }catch(SQLException){}

3.Mysql连接语句://对应mm.mysql-2.0.4-bin.jar

String driver="org.gjt.mm.mysql.Driver"

String url="jdbc:mysql://localhost:3306/zxks"

try {

Class.forName(driver)

con=DriverManager.getConnection(str,"root","")

} catch (ClassNotFoundException e) {

// TODO 自动生成 catch 块

e.printStackTrace()

} catch (SQLException e) {

// TODO 自动生成 catch 块

e.printStackTrace()

}

<driver-url>jdbc:mysql://localhost:3306/GBDSPT </driver-url>

<driver-class>com.mysql.jdbc.Driver</driver-class>

别忘了下驱动


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8712764.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-20
下一篇 2023-04-20

发表评论

登录后才能评论

评论列表(0条)

保存