日期:2014-05-16  浏览次数:20472 次

Java中数据库驱动程序加载及建立连接
//Oracle数据库:
?? Class.forName("oracle.jdbc.driver.OracleDriver");
?? Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl" , "username" , "password");
?? //注:orcl为数据库的SID
//DB2数据库:
?? Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
?? Connection conn = DriverManager.getConnection("jdbc:db2://localhost:5000/dbname" , "username" , "password");
// 注:dbname为数据库名
//SQL Server 数据库:
?? Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
?? Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1443;DatabaseName=dbaname" , "username" , "password");
?? //注:dbname为数据库名
//Sybase数据库:
?? //Class.forName("com.sybase.jdbc.SybDriver");
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");??
Connection conn = DriverManager.getConnection("jdbc:sybase:Tds:localhost:5007/dbname" , "username" , "password");
?? 注:dbname为数据库名
//Informix数据库:
?? Class.forName("com.informix.jdbc.IfxDriver");
//MySQL数据库:
?? Class.forName("org.gjt.mm.mysql.Driver"); 或者 Class.forName("com.mysql.jdbc.Driver");
?? Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname" , "username" , "password");
?? //注:dbname为数据库名

//Postgresql

Class.forName("org.postgresql.Driver");??
?? Connection con = DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");