以前一直使用MS SQL 配置数据库连接池也是在Tomcat 下 Context.xml 配置的  今天刚学习MySQL 想用连接池  但是又不知道MySQL数据库的 driverClassName 和 url  是该怎么写的 上网查了下  都说是在server.xml 中配置的  迷糊了..

解决方案 »

  1.   

    tomcat 6是在context.xml下配 你翻一下帖子这几天都有讲
      

  2.   

    不同数据库的连接池配置就是driverClassName 和 url  不同其他都一样!
      

  3.   


    你修改一下这个试试看
    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
    initialSizse="30" maxActive="100" maxIdle="30" maxWait="10000"
    username="my_user" password="my_password" driverClassName="com.mysql.jdbc.Driver"
    removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
    url="jdbc:mysql://localhost:3306/my_databasename"/>
      

  4.   

    alter table book
    add constraint df_relation default 4 for relation  在MySQl中要设置某列的默认值 该怎么写呢?
      

  5.   

    不过啥数据库都是context.xml中配呢!自己动手试下!
      

  6.   

    我用的是MysQl5.0 tomcat 下 Context.xml 中配置是这样的<Resource name="jdbc/addressbook" auth="Container" type="javax.sql.DataSource" maxActive="100"

    maxIdle="30" maxWait="10000" username="root" password="space"

    driverClassName="org.gjt.mm.mysql.Driver"  url="jdbc:mysql://localhost/addressbook" />连接类中是这样写的public Connection getConnection(){
    try {
    Context ic = new InitialContext();
    DataSource source = (DataSource)ic.lookup("java:comp/env/jdbc/addressbook");
    dbConnection = source.getConnection();
    } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return dbConnection ;
    }
    Web.xml中是这样配置的  <resource-ref>
       <description>addressbook DataSource</description>
       <res-ref-name>jdbc/addressbook</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>
    但是我在写好的那个数据库连接类中写了个main() 测试了下 是连接失败 
    错误指向 DataSource source = (DataSource)ic.lookup("java:comp/env/jdbc/addressBook"); 错在哪了呢?