本文是本站小編搜尋整理的關於使用Java程式連線各種資料庫的8種方法,供參考學習,希望對大家有所幫助!想了解更多相關資訊請持續關注我們應屆畢業生考試網!
1、Oracle8/8i/9i資料庫(thin模式)
ame("leDriver")nstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl為資料庫的SID
String user="test";
String password="test";
Connection conn= onnection(url,user,password);
2、DB2資料庫
ame("2Driver ")nstance();
String url="jdbc:db2://localhost:5000/sample"; //sample為你的`資料庫名
String user="admin";
String password="";
Connection conn= onnection(url,user,password);
3、SQL Server7.0/2000資料庫
ame("erverDriver")nstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb為資料庫
String user="sa";
String password="";
Connection conn= onnection(url,user,password);
4、Sybase資料庫
ame("river")nstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB為你的資料庫名
Properties sysProps = roperties();
("user","userid");
("password","user_password");
Connection conn= onnection(url, SysProps);
5、Informix資料庫
ame("river")nstance();
String url = "jdbc:informix-sqli://:INFORMIXSERVER=myserver;
user=testuser;password=testpassword"; //myDB為資料庫名
Connection conn= onnection(url);
6、MySQL資料庫
ame("er")nstance();
//或者ame("er");
String url ="jdbc:mysql://localhost/myDB?
user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB為資料庫名
Connection conn= onnection(url);
7、PostgreSQL資料庫
ame("er")nstance();
String url ="jdbc:postgresql://localhost/myDB" //myDB為資料庫名
String user="myuser";
String password="mypassword";
Connection conn= onnection(url,user,password);
8、access資料庫直連用ODBC的
ame("OdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Driver
(*)};DBQ="+ealPath("/Data/");
Connection conn = onnection(url,"","");
Statement stmtNew=teStatement() ;
Copyright ©2024 才華齋 All Rights Reserved.