07hnust

导航

常用数据库的JDBC连接代码

//oracle数据库

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

String url="jdbc:oracle:thin:@localhost:1521:xx";

String user="user";

String password="psw";

Connection conn=DriverManager.getConnection(url,user,password);

 

//DB2数据库

Class.forName("com.ibm.db2.jdbc.app,DB2Driver").newInstance();

String user="user";

String password="psw";

String url="jdbc:db2://localhost:5000/xx"

Connection conn=DriverManager.getConnection(url,user,password);

 

//Sybase数据库

Class.forName("com.sybase.jdbc.SybDriver").newInstance();

String url="jdbc:sybase:Tds:localhost:5007/xx"//Sybase数据库

Properties sysProps=System.getProperties();

sysProps.put("user","sa");

sysProps.put("password","");

Connection conn=DriverManager.getConnection(url,sysProps);

 

//Informix数据库

Class.forName("com.informix.jdbc.IfxDriver").newInstance();

String url="jdbc:infoxmix-sqli://localhost:1533/xx:INFORMIXSERVER = myserver;user=xx;password=xx";//Informix数据库

Connection conn=DriverManager.getConnection(url);

 

//MySql数据库

Class.forName("com.gjt.mm.mysql.Driver").newInstance();

String url="jdbc:mysql://localhost/xx?user=xx&password=xx&useUnicode=true&characterEncoding=GB2312";

Connection conn=DriverManager.getConnection(url);

 

//PostgreSQL数据库

Class.forName("org.postgresql.Driver").newInstance();

String user="user";

String password="psw";

String url="jdbc:postgresql://localhost/xx"

Connection conn=DriverManager.getConnection(url,user,password);

posted on 2012-03-14 15:14  07hnust  阅读(184)  评论(0编辑  收藏  举报