jdbc连接常用数据库代码

系统 1763 0
1、 Oracle8/8i/9i 数据库( thin 模式)
Class.forName( " oracle.jdbc.driver.OracleDriver " ).newInstance();
Stringurl
= " jdbc:oracle:thin:@localhost:1521:orcl " ; // orcl为数据库的SID
Stringuser = " test " ;
Stringpassword
= " test " ;
Connectionconn
= DriverManager.getConnection(url,user,password);

2
DB2 数据库
Class.forName( " com.ibm.db2.jdbc.app.DB2Driver " ).newInstance();
Stringurl
= " jdbc:db2://localhost:5000/sample " ; // sample为你的数据库名
Stringuser = " admin " ;
Stringpassword
= "" ;
Connectionconn
= DriverManager.getConnection(url,user,password);

3
SqlServer7.0/2000 数据库
Class.forName( " com.microsoft.jdbc.sqlserver.SQLServerDriver " ).newInstance();
Stringurl
= " jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb " ;
// mydb为数据库
Stringuser = " sa " ;
Stringpassword
= "" ;
Connectionconn
= DriverManager.getConnection(url,user,password);

4
Sybase 数据库
Class.forName( " com.sybase.jdbc.SybDriver " ).newInstance();
Stringurl
= " jdbc:sybase:Tds:localhost:5007/myDB " ; // myDB为你的数据库名
PropertiessysProps = System.getProperties();
SysProps.put(
" user " , " userid " );
SysProps.put(
" password " , " user_password " );
Connectionconn
= DriverManager.getConnection(url,SysProps);

5
Informix 数据库
Class.forName( " com.informix.jdbc.IfxDriver " ).newInstance();
Stringurl
=
" jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword
" ; // myDB为数据库名
Connectionconn = DriverManager.getConnection(url);

6
MySQL 数据库
Class.forName( " org.gjt.mm.mysql.Driver " ).newInstance();
Stringurl
= " jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1 "
// myDB为数据库名
Connectionconn = DriverManager.getConnection(url);

7
PostgreSQL 数据库
Class.forName( " org.postgresql.Driver " ).newInstance();
Stringurl
= " jdbc:postgresql://localhost/myDB " // myDB为数据库名
Stringuser = " myuser " ;
Stringpassword
= " mypassword " ;
Connectionconn
= DriverManager.getConnection(url,user,password);

8、access
数据库直连用ODBC的
Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver " );
Stringurl
= " jdbc:odbc:Driver={MicroSoftAccessDriver(*.mdb)};DBQ= " + application.getRealPath( " /Data/ReportDemo.mdb " );
Connectionconn
= DriverManager.getConnection(url, "" , "" );
StatementstmtNew
= conn.createStatement();

jdbc连接常用数据库代码


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论