Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/myDatabaseName</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- <ResourceLink type="javax.sql.DataSource"
- name="jdbc/localRemarket"
- global="jdbc/remarket"
- />
- <Resource
- type="javax.sql.DataSource"
- name="jdbc/myDatabaseName"
- factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost:3306/myDatabaseName"
- username="myUsername"
- password="myPassword"
- maxActive="1500"
- maxIdle="200"
- maxwait="-1"
- testOnBorrow="true"
- testOnReturn="true"
- testWhileIdle="true"
- validationQuery="SELECT 1"
- timeBetweenEvictionRunsMillis="2000"
- minEvictableIdleTimeMillis="15000"
- removeAbandoned="true"
- removeAbandonedTimeout="5"
- />
- <Resource
- type="javax.sql.DataSource"
- name="jdbc/myDatabaseName"
- factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost:3306/myDatabaseName"
- username="myUsername"
- password="myPassword"
- maxActive="1500"
- maxIdle="200"
- maxwait="-1"
- testOnBorrow="true"
- testOnReturn="true"
- testWhileIdle="true"
- validationQuery="SELECT 1"
- timeBetweenEvictionRunsMillis="2000"
- minEvictableIdleTimeMillis="15000"
- removeAbandoned="true"
- removeAbandonedTimeout="5"
- />
- Connection conn;
- public void openMyConnection() {
- try {
- Properties props = new Properties();
- props.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
- InitialContext ctx = new InitialContext(props);
- Context envCtx = (Context) ctx.lookup("java:comp/env"); // <<<<< PRB HERE
- // error message : Name [java:comp/env] is not bound in this Context. Unable to find [java:comp]
- org.apache.tomcat.jdbc.pool.DataSource ds = (org.apache.tomcat.jdbc.pool.DataSource) envCtx.lookup("jdbc/localDB");
- conn = ds.getConnection();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- props.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
- props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement