//oracle8/8i/9i資料庫(thin模試)
class.forname("oracle.jdbc.driver.oracledriver").newinstance();
//sql server7.0/2000資料庫
class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver").newinstance();
//db2資料庫
class.forname("com.mysql.jdbc.driver").newinstance();
//postgresql資料庫
class.forname("org.postgresql.driver").newinstance();
//oracle8/8i/9i資料庫(thin模試)
string url = "jdbc:oracle:thin:@localhost:1521:orcl";
string user = "scott";
string password = "tiger";
connection conn = drivermanager.getconnection(url, user, password);
//sql server7.0/2000資料庫
string url="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
string user = "sa";
string password = "";
connection conn = drivermanager.getconnection(url, user, password);
//db2資料庫
string url = "jdbc:db2://localhost:5000/sample";
string user = "admin";
string password = "";
connection conn = drivermanager.getconnection(url, user, password);
//informix資料庫
string url = "jdbc:informix-sqli://localhost:1533/testdb:informixserver= myserver";
string user = "testuser";
string password = "testpassword";
connection conn = drivermanager.getconnection(url);
//sybase資料庫
string url = "jdbc:sybase:tds:localhost:5007/tsdata";
properties sysprops = system.getproperties();
sysprops.put("user", "userid");
sysprops.put("password", "user_password");
connection conn = drivermanager.getconnection(url, sysprops);
//mysql資料庫
string url = "jdbc:mysql://localhost:3306/testdb?user=root&password=root& useunicode = true&characterencoding=gb2312";
connection conn = drivermanager.getconnection(url);
//postgresql資料庫
string url = "jdbc:postgresql://localhost/testdb" ;
string user = "myuser";
string password = "mypassword";
donnecton conn = drivermanager.getconnection(url, user, password);
JDBC驅動連線資料庫的方法
連線資料庫的方法中,有很多方法,在windows系統中,我們能夠使用odbc進行資料庫的連線,但是,怎麼連線在其他平台上資料庫,這時,我們就可以使用資料庫廠商提供的資料庫驅動,對於使用廠商驅動,有兩個步驟 2 在jdbc 中,設定特定的驅動程式名稱和url 常見的驅動程式和名稱如下 1 ms sql...
Java中資料庫驅動程式載入及建立連線
oracle資料庫 class.forname oracle.jdbc.driver.oracledriver connection conn drivermanager.getconnection jdbc oracle thin localhost 1521 orcl username pass...
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 ...