JDBC连接字符串

1. MySQL

   Class.forName("org.gjt.mm.mysql.Driver").newInstance();   
   String  url  ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode= true&characterEncoding=8859_1"   
   Connection  conn=  DriverManager.getConnection(url,user,password); 

 

2. ORACLE

   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();   
   String  url="jdbc:oracle:thin:@localhost:1521:orcl";   
   //orcl为数据库的SID   
   String  user="test";   
   String  password="test";   
   Connection  conn=  DriverManager.getConnection(url,user,password); 

 

3. DB2

   Class.forName("com.ibm.db2.jdbc.app.DB2Driver  ").newInstance();   
   String  url="jdbc:db2://localhost:5000/sample";    
   String  user="admin";    
   String  password="";   
   Connection  conn=  DriverManager.getConnection(url,user,password); 

 

4. Microsoft SQLServer

 

        (SqlServer 2000)

            Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );

            conn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs", sUsr, sPwd );

 

        (SqlServer 2005)

            Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );

            conn = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;databaseName=pubs", sUsr, sPwd );

 

5.Microsoft SQL Server series (6.5, 7.x and 2000) and Sybase 10

    JDBC Name: jtds

    URL: http://jtds.sourceforge.net/

    Version: 0.5.1

    Download URL: http://sourceforge.net/project/showfiles.php?group_id=33291

 

  语法:

    Class.forName("net.sourceforge.jtds.jdbc.Driver ");

    Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");

    or

    Connection conn = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");

 

6. PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar

  Class.forName("org.postgresql.Driver").newInstance();    
  String  url  ="jdbc:postgresql://localhost/myDB"   
  String  user="myuser";   
  String  password="mypassword";   
  Connection  conn=  DriverManager.getConnection(url,user,password); 

 

7. Sybase(http://jtds.sourceforge.net)jconn2.jar

  Class.forName("com.sybase.jdbc.SybDriver").newInstance();  
  String url =" jdbc:sybase:Tds:localhost:5007/myDB";
  Properties sysProps = System.getProperties();  
  SysProps.put("user","userid");  
  SysProps.put("password","user_password");  
  Connection conn= DriverManager.getConnection(url, SysProps); 
 

8. informix

  Class.forName("com.informix.jdbc.IfxDriver").newInstance();   
  String  url  = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;   
user=testuser;password=testpassword";    
  Connection  conn=  DriverManager.getConnection(url);

 

9.SAP DB

  Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");

  Connection conn = java.sql.DriverManager.getConnection ( "jdbc:sapdb://" + host + "/" + database_name,user_name, password)

 

10.InterBase

  String url = "jdbc:interbase://localhost/e:/testbed/database/employee.gdb";

  Class.forName("interbase.interclient.Driver");

  //Driver d = new interbase.interclient.Driver (); /* this will also work if you do not want the line above */

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

 

11.HSqlDB

   url:     http://hsqldb.sourceforge.net/

   driver:  org.hsqldb.jdbcDriver

   连接方式有4种,分别为:

    con-str(内存): jdbc:hsqldb.

    con-str(本地): jdbc:hsqldb:/path/to/the/db/dir

    con-strhttp: jdbc:hsqldb:http://dbsrv

    con-strhsql: jdbc:hsqldb:hsql://dbsrv

 

12. ODBC

    strCon  =  "jdbc:odbc:;Driver={Microsoft Access Driver (*.mdb)};DBQ=数据库文件路径"; //此为NO-DSN方式

    strCon  =  "jdbc:odbc:;Driver={SQL Server};server=主机名\\实例名;database=数据库名称";  //此为NO-DSN方式

    strCon  =  "jdbc:odbc:odbcName";//此为ODBC连接方式

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    Connection cn = DriverManager.getConnection( strCon, sUsr, sPwd );

 

13.IBM AS400主机在用的JDBC语法

    有装V4R4以上版本的Client Access Express

    可以在C:\Program Files\IBM\Client Access\jt400\lib

    找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar

    语法:

    java.sql.DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());

    Class.forName("com.ibm.as400.access.AS400JDBCConnection");

    Connection conn = DriverManager.getConnection("jdbc:as400://IP","user","password");

 

你可能感兴趣的:(jdbc)