常用数据库的JDBC连接代码

//常用数据库的JDBC连接代码。


//oracle数据库
class.forName("oracle.jdbc.driver.OracleDrive").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:libSystem";
String user="scott";
String password="tiger";
Connection conn=DriverManager.getConnection(url,user,password);

 

//DB2数据库
class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
String url="jdbc:db2://localhost:5000/libSystem";
String user="db2admin";
String password="db2admin";
Connection conn=DriverManager.getConnection(url,user,password);

//Sybase数据库
class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url="jdbc:sybase:Tds:localhost:5007/libSystem";
Properties sysProps=System.getProperties();
sysProps.put("user","sa");
sysProps.put("password","");
Connection conn=DriverManager.getConnection(url,sysProps);

//Informix数据库
class.forName("com.infoxmix.jdbc.IfxDriver").newInstance();
String url="jdbc:infoxmix-sqli://localhost:1533/libSystem:
 INFORMIXSERVER=myserver;
user=Informix;password=Informix";
Connection conn=DriverManager.getConnection(url);


//MySQL数据库
class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url="jdbc:mysql://localhost/libSystem?user=root&password=root &useUnicode=true &characterEncoding=GB2312";
String user="db2admin";
String password="db2admin";
Connection conn=DriverManager.getConnection(url);

//PostgreSQL数据库
class.forName("org.postgresql.Driver").newInstance();
String url="jdbc:postgresql://localhost/libSystem";
String user="postgreSQL";
String password="postgreSQL";
Connection conn=DriverManager.getConnection(url,user,password);

//SQL Server数据库
String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=YL;SelectMethod=Cursor";
String DBUSER="sa";
String DBPASSWORD="123";
Class.forName(DBDRIVER);                     
Connection conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);

posted @ 2010-08-30 11:43  月亮的影子  阅读(507)  评论(0编辑  收藏  举报