成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

J2EE技術之JDBC連接數(shù)據(jù)庫的各種寫法

開發(fā) 后端
本文講述J2EE技術中的JDBC連接數(shù)據(jù)庫的各種寫法,包括Oracle數(shù)據(jù)庫,DB2,Sql Server等各種主流數(shù)據(jù)庫。

以下是JDBC連接各種數(shù)據(jù)庫的寫法,獻給Java初學者,提一點建議,記得導入對應的驅(qū)動jar包哦。

1、Oracle8/8i/9i數(shù)據(jù)庫(thin模式)

  1. Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();   
  2. String url="jdbc:oracle:thin:@localhost:1521:orcl";   
  3. //orcl為數(shù)據(jù)庫的SID   
  4. String user="test";   
  5. String password="test";   
  6. Connection conn= DriverManager.getConnection(url,user,password);  

2、DB2數(shù)據(jù)庫

  1. Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();   
  2. String url="jdbc:db2://localhost:5000/sample";   
  3. //sample為你的數(shù)據(jù)庫名   
  4. String user="admin";   
  5. String password="";   
  6. Connection conn= DriverManager.getConnection(url,user,password);  

3、Sql Server7.0/2000數(shù)據(jù)庫

  1. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();   
  2. String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";   
  3. //mydb為數(shù)據(jù)庫   
  4. String user="sa";   
  5. String password="";   
  6. Connection conn= DriverManager.getConnection(url,user,password);  

4、Sybase數(shù)據(jù)庫

  1. Class.forName("com.sybase.jdbc.SybDriver").newInstance();   
  2. String url =" jdbc:sybase:Tds:localhost:5007/myDB";   
  3. //myDB為你的數(shù)據(jù)庫名   
  4. Properties sysProps = System.getProperties();   
  5. SysProps.put("user","userid");   
  6. SysProps.put("password","user_password");   
  7. Connection conn= DriverManager.getConnection(url, SysProps);  

5、Informix數(shù)據(jù)庫

  1. Class.forName("com.informix.jdbc.IfxDriver").newInstance();   
  2. String url =   
  3. "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;   
  4. user=testuser;password=testpassword";   
  5. //myDB為數(shù)據(jù)庫名   
  6. Connection conn= DriverManager.getConnection(url);  

6、MySQL數(shù)據(jù)庫

  1. Class.forName("org.gjt.mm.mysql.Driver").newInstance();   
  2. String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"   
  3. //myDB為數(shù)據(jù)庫名   
  4. Connection conn= DriverManager.getConnection(url);  

  1. Class.forName("com.mysql.jdbc.Driver");   
  2. String url="jdbc:mysql://localhost/myDB?        ser=root&password=system";   
  3. conn = DriverManager.getConnection(url);  

7、PostgreSQL數(shù)據(jù)庫

  1. Class.forName("org.postgresql.Driver").newInstance();   
  2. String url ="jdbc:postgresql://localhost/myDB"   
  3. //myDB為數(shù)據(jù)庫名   
  4. String user="myuser";   
  5. String password="mypassword";   
  6. Connection conn= DriverManager.getConnection(url,user,password);  

補充:Sql Server2005數(shù)據(jù)庫

  1. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();   
  2. String url="jdbc:sqlserver://localhost:1433;DatabaseName=mydb";   
  3. //mydb為數(shù)據(jù)庫   
  4. String user="sa";   
  5. String password="";   
  6. Connection conn= DriverManager.getConnection(url,user,password);  

和sql2000 的連接url有點區(qū)別。JDBC連接數(shù)據(jù)庫的方法基本就是上面這些了。

責任編輯:book05 來源: QQ空間
相關推薦

2009-06-19 16:38:45

JDBC簡介J2EE

2009-06-22 11:04:00

Jdbc存儲過程

2009-06-18 16:13:14

J2EE開發(fā)

2009-06-10 14:10:23

J2EE學習J2EE是什么

2009-06-10 13:37:06

J2EE可伸縮性J2EE靈活性J2EE維護

2009-06-11 17:19:47

J2EE設計模式Template

2009-06-23 08:06:46

J2EE體系架構J2EE模型J2EE設計模式

2009-07-06 17:23:34

JDBC連接數(shù)據(jù)庫

2009-06-23 16:48:26

J2EE常見問題J2EE平臺

2011-05-20 09:56:15

J2EE

2009-06-11 17:06:11

J2EE歷史Java EE概述

2009-06-11 17:23:09

J2EE設計模式State模式

2011-05-26 13:54:42

數(shù)據(jù)庫JDBC連接

2009-07-20 15:56:08

JDBC連接數(shù)據(jù)庫步驟

2009-07-14 17:18:23

JDBC怎么連接數(shù)據(jù)庫

2011-05-26 09:27:59

JDBC連接數(shù)據(jù)庫

2009-06-22 17:32:25

J2EE平臺

2009-06-22 17:05:41

Java EEJava企業(yè)應用

2009-06-11 17:11:07

J2EE設計模式工廠模式

2009-06-10 13:30:32

J2EE四層模型客戶層Web層
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲精品女人久久久 | 国产精品1区 | 91佛爷在线观看 | 日韩精品久久 | 国产日产精品一区二区三区四区 | 久久专区 | 337p日本欧洲亚洲大胆 | 欧美国产一区二区三区 | 欧美在线天堂 | 麻豆久久久 | av一级久久 | 伊人导航 | 91视视频在线观看入口直接观看 | 99精品一区二区三区 | 国产亚洲一区二区三区 | 97av在线 | 极品粉嫩国产48尤物在线播放 | 日日操夜夜操天天操 | 国产在线视频一区 | 国产精品69毛片高清亚洲 | 久久久久久久国产精品 | 视频在线亚洲 | 懂色一区二区三区免费观看 | 久久久久国产精品 | 欧美三区在线观看 | 日韩av啪啪网站大全免费观看 | av网站在线看| 日韩精品在线视频免费观看 | 日本激情一区二区 | 在线观看免费av网 | 一级毛片免费视频观看 | 欧美a在线看 | 亚洲国产精品激情在线观看 | 久久精片 | 国产成人91视频 | 日韩2020狼一二三 | 天堂av资源| 国产精品久久久久一区二区 | 精品国产乱码久久久久久闺蜜 | www.久久99| 91在线精品视频 |