各种数据库的JDBC驱动下载及连接字符串URL写法

巫煌
2023-12-01

 各种数据库的JDBC驱动下载及连接字符串URL写法 
sun官方网站上的JDBC驱动列表:
[url=http://java.sun.com/products/jdbc/reference/industrysupport/index.html]http://java.sun.com/products/jdbc/reference/industrysupport/index.html[/url]
数 据 库  说      明  
MySQL  
[url=http://www.mysql.com/products/connector/j/]http://www.mysql.com/products/connector/j/[/url]
Shipped. But need to download the latest for MySQL 4.1 or higher.  
Oracle  
[url=http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html]http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html[/url]
Included.  
SQL Server by jTDS  
[url=http://sourceforge.net/project/showfiles.php?group_id=33291]http://sourceforge.net/project/showfiles.php?group_id=33291[/url]
Included. Support Microsoft SQL Server (6.5, 7, 2000 and 2005)  
Postgres  
[url=http://jdbc.postgresql.org/download.html]http://jdbc.postgresql.org/download.html[/url]
Included 7.3 JDBC 3  
SAP DB  
[url=http://www.sapdb.org/sap_db_jdbc.htm]http://www.sapdb.org/sap_db_jdbc.htm[/url]
Included.  
SyBase by jTDS  
[url=http://jtds.sourceforge.net/]http://jtds.sourceforge.net/[/url]
Included. Support Sybase (10, 11, 12)  

以下内容来自互联网
1. MySQL(
[url=http://www.mysql.com]http://www.mysql.com[/url]
) mysql-connector-java-2.0.14-bin.jar ;
  Class.forName( "org.gjt.mm.mysql.Driver" );
  cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd ); 
2. PostgreSQL(
[url=http://www.de.postgresql.org]http://www.de.postgresql.org[/url]
) pgjdbc2.jar ;
  Class.forName( "org.postgresql.Driver" ); 
  cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd ); 
3. Oracle(
[url=http://www.oracle.com/ip/deploy/database/oracle9i/]http://www.oracle.com/ip/deploy/database/oracle9i/[/url]
) classes12.zip ;
  Class.forName( "oracle.jdbc.driver.OracleDriver" ); 
  cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd ); 
4. Sybase(
[url=http://jtds.sourceforge.net]http://jtds.sourceforge.net[/url]
) jconn2.jar ;
  Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" ); 
  cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd ); 
  //(Default-Username/Password: "dba"/"sql") 
5. Microsoft SQLServer(
[url=http://jtds.sourceforge.net]http://jtds.sourceforge.net[/url]
) ;
  Class.forName( "net.sourceforge.jtds.jdbc.Driver" ); 
  cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd ); 
6. Microsoft SQLServer(
[url=http://www.microsoft.com]http://www.microsoft.com[/url]
) ;
  Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ); 
  cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd ); 
7. ODBC 
  Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); 
  Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd ); 
8.DB2 Class.forName("com.ibm.db2.jdbc.net.DB2Driver"); 
  String url="jdbc:db2://192.9.200.108:6789/SAMPLE" 
  cn = DriverManager.getConnection( url, sUsr, sPwd ); 
9.access由于access并不是作为一项服务运行,所以url的方法对他不适用。access可以通过odbc,也可以通过服务器映射路径的形式找到.mdb文件,参见
[url=http://rmijdbc.objectweb.org/Access/access.html]http://rmijdbc.objectweb.org/Access/access.html[/url]
JDBC API的使用方法
(1)登记并加载JDBC驱动程序;
两种方法:
Class.forName(String drivername);
DriverManager.registerDriver(Driver driver)
(2)建立与SQL数据库的连接;
DriverManager的getConnection()方法:
Connection getConnection(String url):url表示数据库地址字符串;
Connection getConnection(String url,String user,String pwd)
Connection getConnection(String url,Properties info)
(3)传送一个SQL查询;
Connection的createStatement()方法:
Statement createStatement();
Statement可以执行SQL语句,得到SQL查询结果。
(4)获得结果集。
Statement的执行SQL语句方法:
ResultSet executeQuery(String sql):执行select语句
int executeUpdate(String sql):执行更新语句,如insert,delete,update.
(5)检索查询结果。
ResultSet的方法:
boolean next():没有行时返回false;
String getString(String columnName):返回列名对应的值。
posted on 2007-07-01 16:09 和田雨 阅读(153) 评论(1)  编辑 收藏 引用 所属分类: JDBC 

评论
# re: 各种数据库的JDBC驱动下载及连接字符串URL写法 2007-07-02 19:28 和田雨 
为了方便大家查找,整理内容如下: 
1. MySQL(
[url=http://www.mysql.com)mm.mysql-2.0.2-bin.jar]http://www.mysql.com)mm.mysql-2.0.2-bin.jar[/url]

Class.forName( "org.gjt.mm.mysql.Driver" ); 
cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd ); 
2. PostgreSQL(
[url=http://www.de.postgresql.org)pgjdbc2.jar]http://www.de.postgresql.org)pgjdbc2.jar[/url]

Class.forName( "org.postgresql.Driver" ); 
cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd ); 
3. Oracle(
[url=http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip]http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip[/url]

Class.forName( "oracle.jdbc.driver.OracleDriver" ); 
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd ); 
4. Sybase(
[url=http://jtds.sourceforge.net)jconn2.jar]http://jtds.sourceforge.net)jconn2.jar[/url]

Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" ); 
cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd ); 
//(Default-Username/Password: "dba"/"sql") 
5. Microsoft SQLServer(
[url=http://jtds.sourceforge.net]http://jtds.sourceforge.net[/url]

Class.forName( "net.sourceforge.jtds.jdbc.Driver" ); 
cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd ); 
6. Microsoft SQLServer(
[url=http://www.microsoft.com]http://www.microsoft.com[/url]

Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ); 
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd ); 
7. ODBC 
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); 
Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd ); 
8.DB2(新添加) 
Class.forName("com.ibm.db2.jdbc.net.DB2Driver"); 
String url="jdbc:db2://192.9.200.108:6789/SAMPLE" 
cn = DriverManager.getConnection( url, sUsr, sPwd ); 
9.Microsoft SQL Server series (6.5, 7.x and 2000) and Sybase 10 
JDBC Name: jTDS 
URL: 
[url=http://jtds.sourceforge.net/]http://jtds.sourceforge.net/[/url]

Version: 0.5.1 
Download URL: 
[url=http://sourceforge.net/project/showfiles.php?group_id=33291]http://sourceforge.net/project/showfiles.php?group_id=33291[/url]

语法: 
Class.forName("net.sourceforge.jtds.jdbc.Driver "); 
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password"); 
or 
Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password"); 
10.Postgresql 
JDBC Name: PostgreSQL JDBC 
URL: 
[url=http://jdbc.postgresql.org/]http://jdbc.postgresql.org/[/url]

Version: 7.3.3 build 110 
Download URL: 
[url=http://jdbc.postgresql.org/download.html]http://jdbc.postgresql.org/download.html[/url]

语法: 
Class.forName("org.postgresql.Driver"); 
Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password"); 
11.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"); 
con = DriverManager.getConnection("jdbc:as400://IP","user","password"); 
12.informix 
Class.forName("com.informix.jdbc.IfxDriver").newInstance(); 
String url = 
"jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver; 
user=testuser;password=testpassword"; 
Lib:jdbcdrv.zip
Class.forName( "com.sybase.jdbc.SybDriver" ) 
url="jdbc:sybase:Tds:127.0.0.1:2638/asademo"; 
SybConnection connection= (SybConnection)DriverManager.getConnection(url,"dba","sql"); 
13.SAP DB 
Class.forName ("com.sap.dbtech.jdbc.DriverSapDB"); 
java.sql.Connection connection = java.sql.DriverManager.getConnection ( "jdbc:sapdb://" + host + "/" + database_name,user_name, password) 
14.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" ); 
15.HSqlDB 
url: 
[url=http://hsqldb.sourceforge.net/]http://hsqldb.sourceforge.net/[/url]

driver: org.hsqldb.jdbcDriver 
连接方式有4种,分别为: 
con-str(内存): jdbc:hsqldb. 
con-str(本地): jdbc:hsqldb:/path/to/the/db/dir 
con-str(http): jdbc:hsqldb:http://dbsrv 
con-str(hsql): jdbc:hsqldb:hsql://dbsrv 

本文来自ChinaUnix博客,如果查看原文请点:[/b][url]http://blog.chinaunix.net/u/2898/showart_351500.html[/url] 

 类似资料: