Java数据库驱动连接大全

Java数据库驱动连接大全mysql

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);
sql

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);
oracle

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);
app

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);
ide

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);
sqlserver

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);
post

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,"",""); 
url

相关文章
相关标签/搜索