Advertisement
Guest User

Untitled

a guest
May 18th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. envContext = new InitialContext();
  2. DataSource ds = (DataSource) envContext.lookup( "java:/comp/env/jdbc/Database" );
  3. con = ds.getConnection();
  4.  
  5. <resource-ref>
  6. <description>DB Connection</description>
  7. <res-ref-name>jdbc/Database</res-ref-name>
  8. <res-type>javax.sql.DataSource</res-type>
  9. <res-auth>Container</res-auth>
  10. </resource-ref>
  11.  
  12. <?xml version="1.0" encoding="UTF-8"?>
  13. <!-- The contents of this file will be loaded for each web application -->
  14. <Context crossContext="true">
  15.  
  16. <!-- Default set of monitored resources -->
  17. <WatchedResource>WEB-INF/web.xml</WatchedResource>
  18.  
  19. <Resource name="jdbc/Database" auth="Container"
  20. type="javax.sql.DataSource"
  21. maxActive="100" maxIdle="30" maxWait="10000"
  22. username="user"
  23. password="password"
  24. driverClassName="com.mysql.jdbc.Driver"
  25. url="jdbc:mysql://localhost:3306/configerror_db"/>
  26. </Context>
  27.  
  28. Hashtable env = new Hashtable();
  29. env.put(Context.INITIAL_CONTEXT_FACTORY,
  30. "<initialContextFactory>");
  31. env.put(Context.PROVIDER_URL, "<url>");
  32. env.put(Context.SECURITY_PRINCIPAL, "<user>");
  33. env.put(Context.SECURITY_CREDENTIALS, "<password>");
  34. ctx = new InitialContext(env);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement