五种数据库(Mysql,Oracle,SQL Server,Sybase,DB2)的连接操作

(1)Mysql数据库连接操作:

Class.forName("com.mysql.cj.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/testjdbc?serverTimezone=GMT%2B8";
String user="admin";
String passwd="admin";
conn=DriverManager.getConnection(url,user,passwd);

(2) Oracle数据库连接操作

Class.forName("com.jdbc.driver.OracleDeiver");
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String user="admin";
String passwd="admin";
conn=DriverManager.getConnection(url,user,passwd);

(3)DB2数据库连接操作

Class.forName("com.lib.dbw.jdbc.app.DB2Driverr");
String url="jdbc:db2://localhost:3306/sample";
String user="admin";
String passwd="admin";
conn=DriverManager.getConnection(url,user,passwd);

(4)SQL Server数据库连接操作

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
String user="admin";
String passwd="admin";
conn=DriverManager.getConnection(url,user,passwd);

(5)Sybase数据库连接操作

Class.forName("com.sybase.jdbc.SybDriver");
String url="jdbc:sybase:Tds:localhost:5007/test;
properties sysProps=System.getProperties();
sysProps.put=("user","admin");
sysProps.put=("passwd","admin");
conn=DriverManager.getConnection(url,user,passwd);

你可能感兴趣的:(Java入门初学历程)