当前位置:Gxlcms > 数据库问题 > jdbc连接字符串

jdbc连接字符串

时间:2021-07-01 10:21:17 帮助过:21人阅读

MySQL:
String Driver="com.mysql.jdbc.Driver"; //驱动程序
String URL="jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名
String Username="username"; //用户名
String Password="password"; //密码
Class.forName(Driver);
Connection con=DriverManager.getConnection(URL,Username,Password);

Oracle:
String Driver="oracle.jdbc.driver.OracleDriver";  //连接数据库的方法
String URL="jdbc:oracle:thin:@localhost:1521:orcl";  //orcl为数据库的SID
String Username="username"; //用户名
String Password="password"; //密码
Class.forName(Driver) ; //加载数据库驱动
Connection con=DriverManager.getConnection(URL,Username,Password); //常用数据库链接方式

DB2:
String Driver="com.ibm.dbjdbc.app.DBDriver"; //连接具有DB2客户端的Provider实例
//String Driver="com.ibm.dbjdbc.net.DBDriver"; //连接不具有DB2客户端的Provider实例
String URL="jdbc:db2://localhost:5000/db_name"; //db_name为数据库名
String Username="username"; //用户名
String Password="password"; //密码
Class.forName(Driver) ;

jdbc连接字符串

标签:drive   方式   加载   string   驱动程序   for   mys   ring   客户端   

人气教程排行