Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Context>
- <Resource
- name="list"
- type="javax.sql.DataSource"
- maxTotal="12"
- maxIdle="8"
- maxWaitMillis="10000"
- username="abc"
- password="abc"
- driverClassName="org.gjt.mm.mysql.Driver"
- url="jdbc:mysql://localhost/list" />
- </Context>
- <resource-ref>
- <description>MySQL DB Connection Pool</description>
- <res-ref-name>jdbc/list</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- public class ConnectionPool {
- private static final String DATASOURCE_NAME = "jdbc/list";
- private static DataSource dataSource;
- static {
- try {
- Context initContext = new InitialContext();
- Context envContext = (Context) initContext.lookup("java:/comp/env");
- dataSource = (DataSource) envContext.lookup(DATASOURCE_NAME);
- } catch (NamingException e) {
- e.printStackTrace();
- }
- }
- private ConnectionPool() {}
- public static Connection getConnection() throws SQLException {
- Connection connection = dataSource.getConnection();
- return connection;
- }
- }
- Connection connection = dataSource.getConnection();
- java.lang.NullPointerException
- by.gsu.epamlab.services.ConnectionPool.getConnection(ConnectionPool.java:26)
- Tam.doPost(Tam.java:20)
- javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
- javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
- org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Add Comment
Please, Sign In to add comment