服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java与数据库连接方法(三)

最后给出java连接其他数据库的关键代码:

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、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);   
 
4、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);   
 
5、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);   
 
6、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); 

扫描关注微信公众号