您的位置:首页 > 编程语言 > Java开发

Java数据库驱动链接大全

2012-07-18 17:27 246 查看
Java数据库驱动链接大全

MySQL:

String Driver="com.mysql.jdbc.Driver"; //驱动程序

String URL="jdbc:mysql://localhost:3306/db_name"?useUnicode=true&characterEncoding=UTF-8; //连接的URL,db_name为数据库名,注意修改编码类型

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Microsoft SQL Server 2000以下 驱动(3个jar的那个):

String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法

String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Microsoft SQL Server 2005以下 驱动(1个jar的那个):

String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //连接SQL数据库的方法

String URL="jdbc:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Sysbase:

String Driver="com.sybase.jdbc.SybDriver"; //驱动程序

String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name为数据可名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Oracle(用thin模式):

String Driver="oracle.jdbc.driver.OracleDriver"; //连接数据库的方法

String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

PostgreSQL:

String Driver="org.postgresql.Driver"; //连接数据库的方法

String URL="jdbc:postgresql://localhost/db_name"; //db_name为数据可名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

DB2:

String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; //连接具有DB2客户端的Provider实例

//String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; //连接不具有DB2客户端的Provider实例

String URL="jdbc:db2://localhost:5000/db_name"; //db_name为数据可名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Informix:

String Driver="com.informix.jdbc.IfxDriver";

String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name为数据可名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

JDBC-ODBC:

String Driver="sun.jdbc.odbc.JdbcOdbcDriver";

String URL="jdbc:odbc:dbsource"; //dbsource为数据源名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

PostgreSQL数据库

String Driver = "org.postgresql.Driver";

String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名

String username="username"; //用户名

String password="password"; //密码

Class.forName(Driver);

Connection con = DriverManager.getConnection(URL,username,password);

Access数据库直连用ODBC的

String Driver = "sun.jdbc.odbc.JdbcOdbcDriver";

String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");

Class.forName(Driver);

Connection conn = DriverManager.getConnection(url,"","");

本文出自 “艾客” 博客,请务必保留此出处http://jrunner.blog.51cto.com/1015356/934626
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: