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

常用数据库连接测试程序

Oracle:

??Class.forName("oracle.jdbc.driver.OracleDriver");
??Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","zhaozy");
??System.out.println(conn);

?

Mysql:

??Class.forName("com.mysql.jdbc.Driver");
??Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/drp?user=root&password=zhaozy");
??System.out.println(conn);

?

Sybase(ASE):

?? Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
? ?Connection conn=DriverManager.getConnection("jdbc:sybase:Tds:10.32.17.154:5000/master","sa","");
?? System.out.println(conn);


DB2:

??? Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();

??? String url="jdbc:db2://192.168.10.11:50001/vendbs"; //vendbs为数据库名
??? String user="ven";
??? String password="111111";

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









1、Oracle8/8i/9i数据库(thin模式)

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

String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID

String user="test";

String password="test";

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

2、DB2数据库

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

String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名

String user="admin";

String password="";

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

3、SQL Server7.0/2000数据库

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";