java連線各種資料庫的例項

2021-09-11 17:23:04 字數 1902 閱讀 3233

檢視ms sql設定 :dbcc useroption

此文中的**主要列出連線資料庫的關鍵**,其他訪問資料庫**省略

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

3、sql server7.0/2000資料庫 

class.forname("net.sourceforge.jtds.jdbc.driver"); 

string url="jdbc:jtds:sqlserver:"; 

//mydb為資料庫 

string user="sa"; 

string password=""; 

connection conn= drivermanager.getconnection(url,user,password); 

4、sybase資料庫 

class.forname("com.sybase.jdbc.sybdriver").newinstance(); 

string url =" jdbc:sybase:tds:localhost:5007/mydb"; 

//mydb為你的資料庫名 

properties sysprops = system.getproperties(); 

sysprops.put("user","userid"); 

sysprops.put("password","user_password"); 

connection conn= drivermanager.getconnection(url, sysprops); 

5、informix資料庫 

class.forname("com.informix.jdbc.ifxdriver").newinstance(); 

string url = 

"jdbc:informix-sqli: 

user=testuser;password=testpassword"; 

//mydb為資料庫名 

connection conn= drivermanager.getconnection(url); 

6、mysql資料庫 

class.forname("org.gjt.mm.mysql.driver").newinstance(); 

string url ="jdbc:mysql://localhost:3306/mydb?user=soft&password=soft1234&useunicode=true&characterencoding=utf-8" 

//mydb為資料庫名 

connection conn= drivermanager.getconnection

7、postgresql資料庫 

class.forname("org.postgresql.driver").newinstance(); 

string url ="jdbc:postgresql://localhost/mydb" 

//mydb為資料庫名 

string user="myuser"; 

string password="mypassword"; 

connection conn= drivermanager.getconnection(url,user,password); 

Java連線各種資料庫的例項

1 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl orcl為資料庫的sid strin...

Java連線各種資料庫的例項

此文中的 主要列出連線資料庫的關鍵 其他訪問資料庫 省略 1 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost...

Java連線各種資料庫的例項

1 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl orcl為資料庫的sid strin...