MySQL:
String Driver="com.mysql.jdbc.Driver"; //驅動程序
String URL="jdbc:mysql://localhost:3306/db_name"; //連接的URL,db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).new Instance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Microsoft SQL Server :
String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //連接SQL數(shù)據(jù)庫的方法
String URL="jdbc:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).new Instance(); //加載數(shù)據(jù)可驅動
Connection con=DriverManager.getConnection(URL,UserName,Password);
Sysbase:
String Driver="com.sybase.jdbc.SybDriver"; //驅動程序
String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Oracle:
String Driver="oracle.jdbc.driver.OracleDriver"; //連接數(shù)據(jù)庫的方法
String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl為數(shù)據(jù)庫的SID
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).newInstance(); //加載數(shù)據(jù)庫驅動
Connection con=DriverManager.getConnection(URL,Username,Password);
PostgreSQL:
String Driver="org.postgresql.Driver"; //連接數(shù)據(jù)庫的方法
String URL="jdbc:postgresql://localhost/db_name"; //db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
DB2:
String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; //連接具有DB2客戶端的Provider實例
//String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; //連接不具有DB2客戶端的Provider實例
String URL="jdbc:db2://localhost:5000/db_name"; //db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Informix:
String Driver="com.informix.jdbc.IfxDriver";
String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name為數(shù)據(jù)庫名
String Username="username"; //用戶名
String Password="password"; //密碼
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);