daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <Context>
  2.     <Resource
  3.             name="jdbc/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. @WebServlet("/main")
  42. public class Tam extends HttpServlet {
  43.     private static final String INSERT = "INSERT INTO users (name, password) VALUES (?, ?)";
  44.     @Override
  45.     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  46.         try {
  47.             Connection connection = ConnectionPool.getConnection();
  48.             PreparedStatement preparedStatement = connection.prepareStatement(INSERT);
  49.             preparedStatement.setString(1,"abc");
  50.             preparedStatement.setInt(2,123);
  51.             preparedStatement.executeUpdate();
  52.             resp.sendRedirect("/main.jsp");
  53.         } catch (SQLException e){
  54.             System.out.println(e);
  55.             RequestDispatcher requestDispatcher = req.getServletContext().getRequestDispatcher("/error.jsp");
  56.             requestDispatcher.forward(req,resp);
  57.         }
  58.     }
  59. }
  60.    
  61. Connection connection = dataSource.getConnection();
  62.    
  63. Type Exception Report
  64.  
  65. Message Servlet execution threw an exception
  66.  
  67. Description The server encountered an unexpected condition that prevented it from fulfilling the request.
  68.  
  69. Exception
  70.  
  71. javax.servlet.ServletException: Servlet execution threw an exception
  72.     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  73. Root Cause
  74.  
  75. java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
  76.     org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:874)
  77.     org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:270)
  78.     org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:389)
  79.     org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2398)
  80.     org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2381)
  81.     org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2110)
  82.     org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
  83.     by.gsu.epamlab.services.ConnectionPool.getConnection(ConnectionPool.java:26)
  84.     Tam.doPost(Tam.java:20)
  85.     javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
  86.     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
  87.     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  88. Note The full stack trace of the root cause is available in the server logs.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top