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

相關文章
相關標籤/搜索