Advertisement
Javi

Tomcat JNDI/JDBC config

Mar 12th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. context.xml:
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <Context antiJARLocking="true" path="/openbankof">
  5.  
  6. <Resource name="jdbc/bankofds" auth="Container" type="javax.sql.DataSource"
  7. maxActive="100" maxIdle="30" maxWait="10000"
  8. username="app"
  9. password="app"
  10. driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
  11. url="jdbc:derby:c:/temp/datosbankof"/>
  12. </Context>
  13.  
  14. web.xml:
  15.  
  16. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  17. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  19. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  20. version="2.4">
  21. <description>MySQL Test App</description>
  22. <resource-ref>
  23. <description>DB Connection</description>
  24. <res-ref-name>jdbc/bankofds</res-ref-name>
  25. <res-type>javax.sql.DataSource</res-type>
  26. <res-auth>Container</res-auth>
  27. </resource-ref>
  28. </web-app>
  29.  
  30.  
  31. *.java:
  32.  
  33. Context initContext = new InitialContext();
  34. Context envContext = (Context)initContext.lookup("java:/comp/env");
  35. DataSource ds = (DataSource)envContext.lookup("jdbc/bankofds");
  36. Connection conn = ds.getConnection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement