自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

tomcat MySQL數(shù)據(jù)源的實(shí)際操作流程與代碼

數(shù)據(jù)庫(kù) MySQL
本文主要向大家講述的是實(shí)現(xiàn)tomcat MySQL數(shù)據(jù)源的實(shí)際操作流程與在實(shí)際操作中我們要用到的代碼的描述,以下就是文章的主要內(nèi)容。

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

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

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

<Context>節(jié)點(diǎn)下加

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

3.更改工程下的web.xml

<web-app>節(jié)點(diǎn)下加

  1. <resource-ref> 
  2. <description>DB Connection</description> 
  3. <res-ref-name>jdbc/MysqlConnectionPoolTest</res-ref-name> 
  4. <res-type>javax.sql.DataSource</res-type> 
  5. <res-auth>Czh</res-auth> 
  6. </resource-ref> 

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ù)器
     
責(zé)任編輯:佚名 來(lái)源: cnblogs
相關(guān)推薦

2010-06-12 16:54:19

2010-06-07 17:30:16

MySQL配置SSL

2010-06-04 14:18:10

MySQL 分頁(yè)存儲(chǔ)過(guò)

2010-05-28 17:32:11

MySQL命令導(dǎo)數(shù)據(jù)

2010-05-27 17:35:36

MYSQL DELET

2010-05-17 11:26:49

MySQL 多級(jí)同步

2010-05-25 16:31:23

MySQL配置

2010-05-19 10:37:06

MySQL expla

2010-06-07 15:47:05

MySQL 數(shù)據(jù)庫(kù)命令

2010-05-20 17:56:43

2010-06-10 18:08:58

2010-06-12 09:53:19

2010-06-10 17:51:35

2010-05-28 18:16:43

MySQL 操作日志

2010-05-27 14:35:25

MySQL批量導(dǎo)入

2010-05-18 10:07:01

MySQL命令

2010-05-28 13:48:07

MySQL數(shù)據(jù)庫(kù)密碼

2010-05-12 11:27:01

MySQL SQL

2010-05-26 14:55:43

MySQL存儲(chǔ)過(guò)程

2010-05-18 09:40:01

MySQL修改表字段
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)