資料庫鏈結方式速查

2021-04-02 12:34:11 字數 2148 閱讀 5861

下面羅列了各種資料庫使用jdbc連線的方式,可以作為乙個手冊使用。

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

2、db2資料庫

3、sql server7.0/2000資料庫

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

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

8、access資料庫直連用odbc的

其實方式簡單,無非就是要把jdbc加到classpath或所用開發工具可以找尋的目錄.

class.forname() 為載入某個類到虛擬機器中,不過好像用 sun.jdbc.odbc.jdbcodbcdriver.class的方式也可以載入,而且不會丟擲異常.

jdbc鏈結資料庫的方式

1 oracle資料庫 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl orcl為資料庫的sid string user test st...

常用的資料庫鏈結方式

1.用asp鏈結access資料庫 使用odbc dsn baogao uid 使用者名稱 pwd 密碼 使用ole db driver dbq somepath mydb.mdb uid admin pwd password 2.用asp鏈結sql server 資料庫 driver server...

連線各種資料庫方式速查表

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