Guest User

Untitled

a guest
Apr 6th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <Context>
  2. <Resource name="jdbc/BookStoreDB"
  3. auth="Container"
  4. type="javax.sql.DataSource"
  5. driverClassName="com.mysql.jdbc.Driver"
  6. url="jdbc:mysql://localhost:3306/BookStoreDB" />
  7. </Context>
  8.  
  9. <resource-ref>
  10. <res-ref-name>jdbc/BookStoreDB</res-ref-name>
  11. <res-type>javax.sql.DataSource</res-type>
  12. <res-auth>Container</res-auth>
  13. </resource-ref>
  14.  
  15. <context-param>
  16. <param-name>DATABASE_NAME</param-name>
  17. <param-value>jdbc/BookStoreDB</param-value>
  18. </context-param>
  19.  
  20. Context initCtx = new InitialContext();
  21. Context envCtx = (Context) initCtx.lookup("java:comp/env");
  22. DataSource ds = (DataSource) envCtx.lookup(name); //name ัั‚ะพ DATABASE_NAME
  23. connection = ds.getConnection();
Add Comment
Please, Sign In to add comment