Java多種資料庫連線

2021-09-01 22:00:40 字數 2901 閱讀 2064

jdbc-odbc:

string driver="sun.jdbc.odbc.jdbcodbcdriver";  

string url="jdbc:odbc:dbsource"; //dbsource為資料來源名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).newinstance();

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

oracle(thin模式):

string driver="oracle.jdbc.driver.oracledriver";    //連線資料庫的方法  

string url="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl為資料庫的sid

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).newinstance(); //載入資料庫驅動

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

mysql:

string driver="com.mysql.jdbc.driver";    //驅動程式  

string url="jdbc:mysql://localhost:3306/db_name"; //連線的url,db_name為資料庫名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).new instance();

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

db2:

microsoft sql server:

string driver="com.microsoft.jdbc.sqlserver.sqlserverdriver";    //連線sql資料庫的方法  

string url="jdbc:microsoft:sqlserver://localhost:1433;databasename=db_name"; //db_name為資料庫名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).new instance(); //載入資料可驅動

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

sysbase:

string driver="com.sybase.jdbc.sybdriver";    //驅動程式  

string url="jdbc:sysbase://localhost:5007/db_name"; //db_name為資料可名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).newinstance();

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

postgresql:

string driver="org.postgresql.driver";    //連線資料庫的方法  

string url="jdbc:postgresql://localhost/db_name"; //db_name為資料可名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).newinstance();

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

informix:

string driver="com.informix.jdbc.ifxdriver";      

string url="jdbc:informix-sqli://localhost:1533/db_name:informixser=myserver"; //db_name為資料可名

string username="username"; //使用者名稱

string password="password"; //密碼

class.forname(driver).newinstance();

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

***[url]

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...

java各種資料庫連線

mysql string driver com.mysql.jdbc.driver 驅動程式 string url jdbc mysql localhost 3306 db name 連線的url,db name為資料庫名 string username username 使用者名稱 string ...