 |
| |
Java连接各种数据库的实例 |
出处:PConline 责任编辑:lujiezheng |
| [03-7-18 17:05]
| 作者:佚名
| - 此文中的代码主要列出连接数据库的关键代码,其他访问数据库代码省略
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="";
- | |  | -
|  |