Guest User

Untitled

a guest
Sep 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?xml version='1.0' encoding='utf-8'?>
  2. <Context>
  3. <resource
  4. name="jdbc/library"
  5. auth="Container"
  6. description="DB Connection"
  7. username="root"
  8. password="root"
  9. driverClassName="com.mysql.jdbc.Driver"
  10. url="jdbc:mysql://localhost:3306/library"
  11. maxActive="10"
  12. maxIdle="3"
  13. maxWait="100"
  14. factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  15. type="javax.sql.DataSource"></resource>
  16. </Context>
  17.  
  18. <resource-ref>
  19. <description>DB Connection</description>
  20. <res-ref-name>jdbc/library</res-ref-name>
  21. <res-type>javax.sql.DataSource</res-type>
  22. <res-auth>Container</res-auth>
  23. </resource-ref>
  24.  
  25. public void check() {
  26. try {
  27. InitialContext initialContext = new InitialContext();
  28. DataSource dataSource = (DataSource)initialContext.lookup("java:comp/env/jdbc/library");
  29. Connection connection = dataSource.getConnection();
  30. Statement statement = connection.createStatement();
  31. ResultSet resultSet = statement.executeQuery("SELECT * FROM book");
  32. System.out.println(resultSet.next());
  33. } catch (NamingException e) {
  34. e.printStackTrace();
  35. } catch (SQLException e) {
  36. e.printStackTrace();
  37. }
  38. }
Add Comment
Please, Sign In to add comment