jdbc連線集合

2022-09-01 16:21:27 字數 3534 閱讀 3067

jdbc裡統一的使用方法:

class.for(jdbcdrivername);

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

這裡的介面是統一的,不同的是每種資料庫提供的jdbcdriver和url不同。

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

microsoft sql server 2.0驅動(3個jar的那個):

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

microsoft sql server 3.0驅動(1個jar的那個):// 老紫竹完善

string driver="com.microsoft.sqlserver.jdbc.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);

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

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

db2:

//string driver="com.ibm.db2.jdbc.net.db2.driver"; //連線不具有db2客戶端的provider例項

string url="jdbc:db2://localhost:5000/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);

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

JDBC連線出錯

在連線資料庫來運算元據時,出現如下錯誤資訊 org.springframework.beans.factory.xml.xmlbeandefinitionreader loading xml bean definitions from class path resource org springfr...

JDBC連線屬性

hibernate 需要進行資料庫訪問,因此必須設定連線資料庫的相關屬性。所有 hibernate 屬性的名字和語義都在 org.hibernate.cfg.environment 中定義。下面是關於 jdbc 連線配置中最重要的設定。hibernate.connection.driver clas...

JDBC連線屬性

hibernate 需要進行資料庫訪問,因此必須設定連線資料庫的相關屬性。所有 hibernate 屬性的名字和語義都在 org.hibernate.cfg.environment 中定義。下面是關於 jdbc 連線配置中最重要的設定。hibernate.connection.driver clas...