新聞中心
這里有您想知道的互聯(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
- type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://127.0.0.1:3306/test"
- username="root" password="000000" maxActive="20" maxIdle="10"
- maxWait="-1"/>
3.更改工程下的web.xml
DB Connection jdbc/MysqlConnectionPoolTest javax.sql.DataSource Czh
4.tomcat MySQL數(shù)據(jù)源代碼如下
- Context context = null;
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- public void DoQuery(String sql) {
- try {
- if(context==null)
- {
- context = new InitialContext();
- }
- // get ds
- DataSource ds = (DataSource) context
- .lookup("java:comp/env/jdbc/MysqlConnectionPoolTest");
- // get conn
- if(conn==null){
- conn = ds.getConnection();
- }
- if(stmt==null){
- stmt = conn.createStatement();
- }
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- String a = rs.getString("a");
- String b = rs.getString("b");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
注意有comp/env/
- context
- .lookup("java:comp/env/jdbc/MysqlConnectionPoolTest");
以上的相關(guān)內(nèi)容就是對(duì)tomcat MySQL數(shù)據(jù)源的介紹,望你能有所收獲。
【編輯推薦】
- Linux mysql就用fedora的自動(dòng)安裝
- Ubuntu mysql配置設(shè)置過(guò)程
- CentOS系統(tǒng)5編譯安裝mysql-4.1.22
- CentOS系統(tǒng)操作mysql的常用命令
- Ubuntu MySQL設(shè)置同步服務(wù)器
當(dāng)前名稱(chēng):tomcatMySQL數(shù)據(jù)源的實(shí)際操作流程與代碼
路徑分享:http://www.dlmjj.cn/article/dppcdcp.html


咨詢(xún)
建站咨詢(xún)
