JDBC ALL CONNECTION

作者在 2008-09-29 11:38:44 发布以下内容
JDBC 数据库连接字符串总结

jtds连接:
驱动
Class.forName("net.sourceforge.jtds.jdbc.Driver");

DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
或new net.sourceforge.jtds.jdbc.Driver();
连接字符串:
"jdbc:jtds:sqlserver://localhost/bbs;user=sa;password="

"jdbc:jtds:sqlserver://localhost:1433/数据库名";
用户名和密码在Conenction里写,其中的1433端口可不加

JDBC-ODBC桥接:
//加载jdbc-odbc驱动程序
class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//通过数据源连接:
String url ="jdbc:odbc:YourDSN";
String user= "sa";
String password ="";
Connection conn = DriverManager.getConnection(url,user,password);
不配置数据的方法:
//加载驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");      
//连接字符串     
String url="jdbc:odbc:Driver={SQL Server};server=.;user=sa;pwd=;database=pubs";
 
Oracle;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:oraDB";
    Connection conn = DriverManager.getConnection(url,"system","manager");
 
SqlServer:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//然后要设置连接
String url="jdbc:microsoft:sqlserver://yourserver:port;DatabaseName=yourdatabase";
Connection conn= DriverManager.getConnection(url,"uername","password");
 
MySql:
Class.forName("org.gjt.mm.mysql.Driver"); 或"com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost/testDB?user=root&password=root"
//testDB为你的数据库名
Connection conn= DriverManager.getConnection(url);
 
Sybase:
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
DriverManager.getConnection("jdbc:sybase:Tds:yourserver:2638?ServiceName=database",user,password);
 
Postgresql:
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");
 
DB2:
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
String url="jdbc:db2://yourserver:6789/SAMPLE";
DriverManager.getConnection(url,sUsr,sPwd);
 
Informix:
Class.forName("com.informix.jdbc.IfxDriver");
String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword";
//myDB为数据库名
Connection conn= DriverManager.getConnection(url,user,password);

 

J2EE | 阅读 2542 次
文章评论,共0条
游客请输入验证码
浏览581655次