JDBC 数据库常用连接 链接字符串
程序员文章站
2022-05-17 08:48:19
1、oracle8/8i/9i数据库(thin模式) class.forname("oracle.jdbc.driver.oracledriver").newinstanc...
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数据库
class.forname("com.ibm.db2.jdbc.app.db2driver ").newinstance();
string url="jdbc:db2://localhost:5000/sample";
//sample为你的数据库名
string user="admin";
string password="";
connection conn= drivermanager.getconnection(url,user,password);
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);
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数据库
class.forname("com.ibm.db2.jdbc.app.db2driver ").newinstance();
string url="jdbc:db2://localhost:5000/sample";
//sample为你的数据库名
string user="admin";
string password="";
connection conn= drivermanager.getconnection(url,user,password);
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);