jdbc連接字符串


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) ;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM