jdbc鏈結資料庫的方式

2021-04-14 13:31:38 字數 2053 閱讀 5878

1、oracle資料庫

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 server資料庫

class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver").newinstance();

string url="jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb";

//mydb為資料庫

string user="sa";

string password="";

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

//使用jtds鏈結sql server資料庫

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

conn = drivermanager.getconnection("jdbc:jtds:sqlserver://ip:port;databasename=dbname", user,pwd);

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://123.45.67.89:1533/mydb:informixserver=myserver;

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/mydb?user=soft&password=soft1234&useunicode=true&characterencoding=8859_1"

//mydb為資料庫名

connection conn= drivermanager.getconnection(url);

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

Jdbc 鏈結資料庫

try rs.close ps.close conn.close try catch exception e if rs null if ps null if conn null catch sqlexception e console cpbm 09110444 資源已經釋放!ps is not ...

JDBC鏈結資料庫

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

jdbc鏈結資料庫

1.鏈結資料庫 1.註冊驅動 2.獲取鏈結物件 3.獲取語句執行物件 4.處理結果集 5.釋放資源 public static void main string args throws classnotfoundexception,sqlexception 2.專案通用格式 1.view層,處理頁面...