新聞中心
JDBC連接各種數(shù)據(jù)庫是大家在日常工作中經(jīng)常要用到的,本文中就為大家總結(jié)了JDBC連接各種數(shù)據(jù)庫方法,希望對大家能夠有所幫助。

成都創(chuàng)新互聯(lián)成立于2013年,先為萬年等服務(wù)建站,萬年等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為萬年企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl為數(shù)據(jù)庫的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
2、DB2數(shù)據(jù)庫
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample";
//sample為你的數(shù)據(jù)庫名
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
3、Sql Server7.0/2000數(shù)據(jù)庫
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb為數(shù)據(jù)庫
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
4、Sybase數(shù)據(jù)庫
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";
//myDB為你的數(shù)據(jù)庫名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
5、Informix數(shù)據(jù)庫
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url =
"jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword";
//myDB為數(shù)據(jù)庫名
Connection conn= DriverManager.getConnection(url);
6、MySQL數(shù)據(jù)庫
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicod
e=true&characterEncoding=8859_1"
//myDB為數(shù)據(jù)庫名
Connection conn= DriverManager.getConnection(url);
7、PostgreSQL數(shù)據(jù)庫
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB"
//myDB為數(shù)據(jù)庫名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
關(guān)于JDBC連接的數(shù)據(jù)庫就為大家列舉了上文中的七種,相信大家通過上文的學(xué)習(xí)之后,現(xiàn)在對JDBC連接各種數(shù)據(jù)庫的方法已經(jīng)有所了解,這樣在以后的工作中遇到類似的問題就能夠輕松解決了,希望大家都能夠從上文中涉及到的內(nèi)容中有所收獲。
當(dāng)前名稱:JDBC連接各種數(shù)據(jù)庫方法
標(biāo)題URL:http://m.fisionsoft.com.cn/article/copooje.html


咨詢
建站咨詢
