日期:2014-05-16 浏览次数:20503 次
<Context docBase="HelloWeb" path="/HelloWeb" reloadable="true" source="org.eclipse.jst.jee.server:HelloWeb"> <Resource name="jdbc/msg" auth="Container" type="javax.sql.DataSource" username="root" password="root" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" maxActive="8" maxIdle="4"/> </Context>
Connection conn = null; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/test"); conn = ds.getConnection(); //conn.close(); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block }