Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Context>
- <Resource
- name="jdbc/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;
- }
- }
- @WebServlet("/main")
- public class Tam extends HttpServlet {
- private static final String INSERT = "INSERT INTO users (name, password) VALUES (?, ?)";
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- try {
- Connection connection = ConnectionPool.getConnection();
- PreparedStatement preparedStatement = connection.prepareStatement(INSERT);
- preparedStatement.setString(1,"abc");
- preparedStatement.setInt(2,123);
- preparedStatement.executeUpdate();
- resp.sendRedirect("/main.jsp");
- } catch (SQLException e){
- System.out.println(e);
- RequestDispatcher requestDispatcher = req.getServletContext().getRequestDispatcher("/error.jsp");
- requestDispatcher.forward(req,resp);
- }
- }
- }
- Connection connection = dataSource.getConnection();
- Type Exception Report
- Message Servlet execution threw an exception
- Description The server encountered an unexpected condition that prevented it from fulfilling the request.
- Exception
- javax.servlet.ServletException: Servlet execution threw an exception
- org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
- Root Cause
- java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
- org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:874)
- org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:270)
- org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:389)
- org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2398)
- org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2381)
- org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2110)
- org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
- 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)
- Note The full stack trace of the root cause is available in the server logs.
Add Comment
Please, Sign In to add comment