在项目中META INF下创建context.xml获得mysql数据库连接池,
<Context>
<Resource name="jdbc/zwjtest"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8"
username="root" password="ZWJ" maxActive="10" maxIdle="10"
maxWait="-1"/>
</Context>
jdbc/zwjtest中的zwjtest是项目名称还是数据库名称?我在用测试类测试时
报错:javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialDataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/zwjtest");没有获得ds.....
<Context>
<Resource name="jdbc/zwjtest"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8"
username="root" password="ZWJ" maxActive="10" maxIdle="10"
maxWait="-1"/>
</Context>
jdbc/zwjtest中的zwjtest是项目名称还是数据库名称?我在用测试类测试时
报错:javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialDataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/zwjtest");没有获得ds.....
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
Object obj = (Object) ctx.lookup("jdbc/zwjtest");
DataSource ds = (javax.sql.DataSource)obj;