Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- envContext = new InitialContext();
- DataSource ds = (DataSource) envContext.lookup( "java:/comp/env/jdbc/Database" );
- con = ds.getConnection();
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/Database</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- The contents of this file will be loaded for each web application -->
- <Context crossContext="true">
- <!-- Default set of monitored resources -->
- <WatchedResource>WEB-INF/web.xml</WatchedResource>
- <Resource name="jdbc/Database" auth="Container"
- type="javax.sql.DataSource"
- maxActive="100" maxIdle="30" maxWait="10000"
- username="user"
- password="password"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost:3306/configerror_db"/>
- </Context>
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "<initialContextFactory>");
- env.put(Context.PROVIDER_URL, "<url>");
- env.put(Context.SECURITY_PRINCIPAL, "<user>");
- env.put(Context.SECURITY_CREDENTIALS, "<password>");
- ctx = new InitialContext(env);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement