使用JDBC連線各種資料庫

2021-06-16 02:48:38 字數 3665 閱讀 8952

使用

jdbc

連線各種資料庫

1、連線

oracle 8/8i/9i

資料庫class.forname("oracle.jdbc.driver.oracledriver");

string url=」jdbc: oracle:thin:@192.168.0.1:1521:orcl」;

string user=」test」;

string password=」test」;

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

oracle.jdbc.driver.oracledriver

:驅動程式類的名稱

jdbc: oracle:thin:

使用thin

模式連線

192.168.0.1:

資料庫的

ip 位址

1521:

資料庫服務的埠號。這是

oracle

的預設值。

orcl:

資料庫的

sid

user:

訪問資料庫的使用者名稱。

password:

訪問資料庫的密碼。

2、連線

db2資料庫

string url=」jdbc:db2:

string user=」admin」;

string password=」」;

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

:驅動程式類的名稱

127.0.0.1

:資料庫的

ip 位址

5000:

資料庫服務的埠號。

sample:

資料庫的名稱。

user:

訪問資料庫的使用者名稱。

password:

訪問資料庫的密碼。

3、連線

sql server 7.0/2000

資料庫class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver");

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

string user=」sa」;

string password=」」;

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

com.microsoft.jdbc.sqlserver.sqlserverdriver

:驅動程式類的名稱

localhost

:資料庫的位址

1433:

資料庫服務的埠號。

mydb:

資料庫的名稱

user:

訪問資料庫的使用者名稱。

password:

訪問資料庫的密碼。

4、連線

sybase

資料庫class.forname("com.sybase.jdbc.sybdriver");

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

properties sysprops=system.getproperties();

syspros.put(「user」,」userid」);

syspros.put(「password」,」user_password」);

connection con = drivermanager.getconnection(url);

com.sybase.jdbc.sybdriver

:驅動程式類的名稱

localhost

:資料庫的位址

5007:

資料庫服務的埠號。

mydb:

資料庫的名稱

userid:

訪問資料庫的使用者名稱。

user_password:

訪問資料庫的密碼。

5、連線

informix

資料庫class.forname("com.informix.jdbc.ifxdriver");

string url=」jdbc:informix-sqli:

myserver;user=testuser;password=testpassword」;

connection con = drivermanager.getconnection(url);

com.informix.jdbc.ifxdriver

:驅動程式類的名稱

123.45.67.89

:資料庫的位址

1533:

資料庫服務的埠號。

mydb:

資料庫的名稱

myserver

:資料庫伺服器的名稱。

tstuser:

訪問資料庫的使用者名稱。

tsetpassword:

訪問資料庫的密碼。

6、連線

mysql

資料庫class.forname("org.git.mm.mysql.driver");

stringurl=」jdbc:mysql://localhost/mydb?user=soft&password=soft1234&useunicode=true&characterencoding=8895_1」

connection con = drivermanager.getconnection(url);

org.git.mm.mysql.driver

:驅動程式類的名稱

localhost

:資料庫的位址

mydb:

資料庫的名稱

soft

:訪問資料庫的使用者名稱。

soft1234:

訪問資料庫的密碼。

8895_1:

使用的字符集。

7、連線

postgresql

資料庫class.forname("org.postgresql.driver");

string url=」jdbc:postgresql://localhost/mydb」;

string user=」myuser」;

string password=」mypassword」;

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

org.postgresql.driver

:驅動程式類的名稱

localhost

:資料庫的位址

mydb:

資料庫的名稱

myuser

:訪問資料庫的使用者名稱。

mypassword:

訪問資料庫的密碼。

8、連線

access

資料庫class.forname("sun.jdbc.odbc.jdbcodbcdriver");

connection con = drivermanager.getconnection("jdbc:odbc:sun", "", "");

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 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl orcl為資料庫的sid strin...

JDBC連線各種資料庫

下文中羅列了各種資料庫使用jdbc連線的方式,大家可以將其作為乙個手冊使用。1 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin ...