【文件属性】:
文件名称:JDBC连接各种数据库字符串大全
文件大小:3KB
文件格式:TXT
更新时间:2014-05-03 09:44:48
JDBC 连接各种数据库字符串大全
JDBC连接字符串大全
racle8/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);
1、SQL Server2005/2008数据库
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
// for SQL Server 2008/2005
String DBDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String DBLocation="jdbc:sqlserver://localhost:1433;DatabaseName=dbname"; //dbname就是要连接的数据库名
String DBUser="sa";
String DBPwd="sa";
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";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
网友评论
- 很不错,按照指导完成了连接oracle10g的测试,不过希望能增加连接其他数据库的讲解,谢谢楼主