JDBC连接MySQL和Oracle
发布网友
发布时间:2022-04-26 21:43
我来回答
共1个回答
热心网友
时间:2022-05-02 00:13
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();
}