DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

yuan has posted 7 posts at DZone. View Full User Profile

Jdbc 连接大全

12.26.2007
| 12396 views |
  • submit to reddit
        // description of your code here

   1. 各种数据库的JDBC连接大全  
   2. Microsoft SQL Server series (6.5, 7.x and 2000) and Sybase 10  
   3.   
   4. JDBC Name: jTDS  
   5. URL: http://jtds.sourceforge.net/  
   6. Version: 0.5.1  
   7. Download URL: http://sourceforge.net/project/showfiles.php?group_id=33291  
   8.   
   9. 语法:   
  10. Class.forName("net.sourceforge.jtds.jdbc.Driver ");  
  11. Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");  
  12. or  
  13. Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");  
  14.   
  15. MySQL  
  16.   
  17. JDBC Name: Connector/J 3.0  
  18. URL: http://www.mysql.com/  
  19. Version: 3.0.8-stable  
  20. Download URL: http://www.mysql.com/downloads/api-jdbc-stable.html  
  21.   
  22. 语法:  
  23. Download URL: http://www.mysql.com/downloads/api-jdbc-stable.html  
  24.   
  25. 语法:   
  26. Class.forName("com.mysql.jdbc.Driver");  
  27. Connection con = DriverManager.getConnection("jdbc:mysql://host:port/database","user","password");  
  28.   
  29. Oracle  
  30.   
  31. JDBC Name: Connector/J 3.0  
  32. URL: http://otn.oracle.com/  
  33. Version: 3.0.8-stable  
  34. Download URL: http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html  
  35.   
  36. 语法:  
  37. Download URL: http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html  
  38.   
  39. 语法:   
  40. Class.forName("oracle.jdbc.driver.OracleDriver");  
  41. Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:port:databse","user","password");  
  42.   
  43. Sybase  
  44.   
  45. Driver: jConnect 4.5/5.5 (JDBC 2.0 请使用5.5)   
  46.   
  47. 语法:  
  48.   
  49. Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();  
  50. DriverManager.getConnection("jdbc:sybase:Tds:IP地址:2638?ServiceName="+数据库名称,"账号","密码");  
  51.   
  52. Postgresql  
  53.   
  54. JDBC Name: PostgreSQL JDBC  
  55. URL: http://jdbc.postgresql.org/  
  56. Version: 7.3.3 build 110  
  57. Download URL: http://jdbc.postgresql.org/download.html  
  58.   
  59. 语法:  
  60. Download URL: http://jdbc.postgresql.org/download.html  
  61.   
  62. 语法:   
  63. Class.forName("org.postgresql.Driver");   
  64. Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");  
  65.   
  66. IBM AS400主机在用的JDBC语法  
  67.   
  68. 有装V4R4以上版本的Client Access Express  
  69. 可以在C:Program FilesIBMClient Accessjt400lib  
  70. 找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar  
  71.   
  72. 语法语法:  
  73. Class.forName("net.sourceforge.jtds.jdbc.Driver ");  
  74. Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");  
  75. or  
  76. Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");  
  77.   
  78. MySQL  
  79.   
  80. JDBC Name: Connector/J 3.0  
  81. URL: http://www.mysql.com/  
  82. Version: 3.0.8-stable  
  83. Download URL: http://www.mysql.com/downloads/api-jdbc-stable.html  
  84.   
  85. 语法:  
  86. Download URL: http://www.mysql.com/downloads/api-jdbc-stable.html  
  87.   
  88. 语法:   
  89. Class.forName("com.mysql.jdbc.Driver");  
  90. Connection con = DriverManager.getConnection("jdbc:mysql://host:port/database","user","password");  
  91.   
  92. Oracle  
  93.   
  94. JDBC Name: Connector/J 3.0  
  95. URL: http://otn.oracle.com/  
  96. Version: 3.0.8-stable  
  97. Download URL: http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html  
  98.   
  99. 语法:  
 100. Download URL: http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html  
 101.   
 102. 语法:   
 103. Class.forName("oracle.jdbc.driver.OracleDriver");  
 104. Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:port:databse","user","password");  
 105.   
 106. Sybase  
 107.   
 108. Driver: jConnect 4.5/5.5 (JDBC 2.0 请使用5.5)   
 109.   
 110. 语法:  
 111.   
 112. Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();  
 113. DriverManager.getConnection("jdbc:sybase:Tds:IP地址:2638?ServiceName="+数据库名称,"账号","密码");  
 114.   
 115. Postgresql  
 116.   
 117. JDBC Name: PostgreSQL JDBC  
 118. URL: http://jdbc.postgresql.org/  
 119. Version: 7.3.3 build 110  
 120. Download URL: http://jdbc.postgresql.org/download.html  
 121.   
 122. 语法:  
 123. Download URL: http://jdbc.postgresql.org/download.html  
 124.   
 125. 语法:   
 126. Class.forName("org.postgresql.Driver");   
 127. Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");  
 128.   
 129. IBM AS400主机在用的JDBC语法  
 130.   
 131. 有装V4R4以上版本的Client Access Express  
 132. 可以在C:Program FilesIBMClient Accessjt400lib  
 133. 找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar  
 134.   
 135. 语法  
 136. java.sql.DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());  
 137. Class.forName("com.ibm.as400.access.AS400JDBCConnection");  
 138. con = DriverManager.getConnection("jdbc:as400://IP","user","passwor");   
 139.   
 140. 1.Oracle8/8i/9i数据库(thin模式)  
 141. Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();   
 142. String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID   
 143. String user="test";   
 144. String password="test";   
 145. Connection conn= DriverManager.getConnection(url,user,password);  
 146. 2.DB2数据库  
 147. Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();   
 148. String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名   
 149. String user="admin";   
 150. String password="";   
 151. Connection conn= DriverManager.getConnection(url,user,password);  
 152. 3.Sql Server7.0/2000数据库  
 153. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();   
 154. String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";   
 155. //mydb为数据库   
 156. String user="sa";   
 157. String password="";   
 158. Connection conn= DriverManager.getConnection(url,user,password);  
 159. 4.Sybase数据库  
 160. Class.forName("com.sybase.jdbc.SybDriver").newInstance();   
 161. String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名   
 162. Properties sysProps = System.getProperties();   
 163. SysProps.put("user","userid");   
 164. SysProps.put("password","user_password");   
 165. Connection conn= DriverManager.getConnection(url, SysProps);  
 166. 5.Informix数据库  
 167. Class.forName("com.informix.jdbc.IfxDriver").newInstance();   
 168. String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;  
 169. user=testuser;password=testpassword"; //myDB为数据库名   
 170. Connection conn= DriverManager.getConnection(url);  
 171. 6.MySQL数据库  
 172. Class.forName("org.gjt.mm.mysql.Driver").newInstance();   
 173. String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"   
 174. //myDB为数据库名   
 175. Connection conn= DriverManager.getConnection(url);  
 176. 7.PostgreSQL数据库  
 177. Class.forName("org.postgresql.Driver").newInstance();   
 178. String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名   
 179. String user="myuser";   
 180. String password="mypassword";   
 181. Connection conn= DriverManager.getConnection(url,user,password);  
 182. 8.access数据库直连用ODBC的  
 183. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;  
 184. String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");  
 185. Connection conn = DriverManager.getConnection(url,"","");  
 186. Statement stmtNew=conn.createStatement() ;