赞
踩
JDBC
连接各种数据库的方法(经典)
1)
连接
Oracle 8/8i/9i/10g/11g
(
thin
模式)
Class.forName("oracle.JDBC.driver.OracleDriver").newInstance();
String url="JDBC:oracle:thin:@localhost:1521:orcl"
//orcl
为
Oracle
数据库的
SID
String user="test";
String password="test";
Connection con=DriverManager.getConnection(url,user,password);
2)
连接
DB2
数据库
Class.forName("com.ibm.db2.jcc.DB2Driver");
String url="JDBC:db2://localhost:5000/testDb";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
3)
连接
MySQL
数据库
Class.forName("com.mysql.jdbc.Driver");
String url="JDBC:mysql://localhost:8080/testDB";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
4)
连接
SQL Server2000
数据库
Class.forName("com.microsoft.JDBC.sqlserver.SQLServerDriver");
String url="JDBC:microsoft:sqlserver://localhost:1433;DatabaseName=testDb";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。