Guest User

Untitled

a guest
Sep 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <Context>
  2. <Resource
  3. name="list"
  4. type="javax.sql.DataSource"
  5. maxTotal="12"
  6. maxIdle="8"
  7. maxWaitMillis="10000"
  8. username="abc"
  9. password="abc"
  10. driverClassName="org.gjt.mm.mysql.Driver"
  11. url="jdbc:mysql://localhost/list" />
  12. </Context>
  13.  
  14. <resource-ref>
  15. <description>MySQL DB Connection Pool</description>
  16. <res-ref-name>jdbc/list</res-ref-name>
  17. <res-type>javax.sql.DataSource</res-type>
  18. <res-auth>Container</res-auth>
  19. </resource-ref>
  20.  
  21. public class ConnectionPool {
  22.  
  23. private static final String DATASOURCE_NAME = "jdbc/list";
  24. private static DataSource dataSource;
  25. static {
  26. try {
  27. Context initContext = new InitialContext();
  28. Context envContext = (Context) initContext.lookup("java:/comp/env");
  29. dataSource = (DataSource) envContext.lookup(DATASOURCE_NAME);
  30. } catch (NamingException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. private ConnectionPool() {}
  35. public static Connection getConnection() throws SQLException {
  36. Connection connection = dataSource.getConnection();
  37. return connection;
  38. }
  39. }
  40.  
  41. Connection connection = dataSource.getConnection();
  42.  
  43. java.lang.NullPointerException
  44. by.gsu.epamlab.services.ConnectionPool.getConnection(ConnectionPool.java:26)
  45. Tam.doPost(Tam.java:20)
  46. javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
  47. javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
  48. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Add Comment
Please, Sign In to add comment