日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
tomcatMySQL數(shù)據(jù)源的實(shí)際操作流程與代碼

以下的文章主要向大家描述的是tomcat MySQL數(shù)據(jù)源的實(shí)際操作流程以及在其實(shí)際操作中所要用到的代碼的描述,假如你對(duì)實(shí)現(xiàn)tomcat MySQL數(shù)據(jù)源的實(shí)際操作感興趣的話,以下的文章將會(huì)滿(mǎn)足你這一興趣。

1.拷相應(yīng)的driver.jar到Tomcat5\common\lib下

2.更改Tomcat5\conf下的context.xml

節(jié)點(diǎn)下加

 
 
 
  1. type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" 
  2. url="jdbc:mysql://127.0.0.1:3306/test" 
  3. username="root" password="000000" maxActive="20" maxIdle="10" 
  4. maxWait="-1"/>  

3.更改工程下的web.xml

節(jié)點(diǎn)下加

 
 
 
  1.  
  2. DB Connection 
  3. jdbc/MysqlConnectionPoolTest 
  4. javax.sql.DataSource 
  5. Czh 
  6.  

4.tomcat MySQL數(shù)據(jù)源代碼如下

 
 
 
  1. Context context = null;  
  2. Connection conn = null;  
  3. Statement stmt = null;  
  4. ResultSet rs = null;  
  5. public void DoQuery(String sql) {  
  6. try {  
  7. if(context==null)  
  8. {  
  9. context = new InitialContext();  
  10. }  
  11. // get ds  
  12. DataSource ds = (DataSource) context  
  13. .lookup("java:comp/env/jdbc/MysqlConnectionPoolTest");  
  14. // get conn  
  15. if(conn==null){  
  16. conn = ds.getConnection();  
  17. }  
  18. if(stmt==null){  
  19. stmt = conn.createStatement();  
  20. }  
  21. rs = stmt.executeQuery(sql);  
  22. while (rs.next()) {  
  23. String a = rs.getString("a");  
  24. String b = rs.getString("b");  
  25. }  
  26. } catch (Exception e) {  
  27. e.printStackTrace();  
  28. }  
  29. }  

注意有comp/env/

 
 
 
  1. context  
  2. .lookup("java:comp/env/jdbc/MysqlConnectionPoolTest");  

以上的相關(guān)內(nèi)容就是對(duì)tomcat MySQL數(shù)據(jù)源的介紹,望你能有所收獲。

【編輯推薦】

  1. Linux mysql就用fedora的自動(dòng)安裝
  2. Ubuntu mysql配置設(shè)置過(guò)程
  3. CentOS系統(tǒng)5編譯安裝mysql-4.1.22
  4. CentOS系統(tǒng)操作mysql的常用命令
  5. Ubuntu MySQL設(shè)置同步服務(wù)器
     

當(dāng)前名稱(chēng):tomcatMySQL數(shù)據(jù)源的實(shí)際操作流程與代碼
路徑分享:http://www.dlmjj.cn/article/dppcdcp.html