如题

解决方案 »

  1.   

    <Context>
    <Resource name="jdbc/bnyxt" type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver" maxIdle="2" maxWait="5000"
    username="root" password="000000"
    url="jdbc:mysql://localhost:3306/bnyxt?characterEncoding=UTF-8"
    maxActive="5" />
    </Context>
    Context initCtx = new InitialContext();
    Context ctx = (Context) initCtx.lookup("java:comp/env");
    javax.sql.DataSource ds = (javax.sql.DataSource) ctx
    .lookup("jdbc/bnyxt");
    conn = ds.getConnection();
      

  2.   

    JNDI接口,数据源,数据库连接池!
      

  3.   

    用过jndi,想知道原理,学习~
      

  4.   


    这个是TOMCAT里进行的JNDI连接池配置,第一个文件在TOMCAT安装目录的CONF下的 context.xml
    第二个是类里获取连接的方法 顺便说一下 用好的连接得CLOSE 不然池就满了。TOMCAT就DOWN了