Guest User

Untitled

a guest
Jan 2nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public class MysqlConnectionPool {
  2. private final DataSource dataSource;
  3.  
  4. public MysqlConnectionPool() {
  5. MysqlConnectionPoolDataSource pool = new MysqlConnectionPoolDataSource();
  6. pool.setUrl("jdbc:mysql://*********.sa-east-1.rds.amazonaws.com:3306/*********?autoReconnect=true&useSSL=false");
  7. pool.setUser("*********");
  8. pool.setPassword("*********");
  9.  
  10. this.dataSource = pool;
  11. }
  12. public Connection getConnection() throws SQLException {
  13. Connection connection = dataSource.getConnection();
  14. return connection;
  15. }}
  16.  
  17. public class UsuarioDAO {
  18. ExceptionHandling capturaException = new ExceptionHandling();
  19. GeradorURL geradorURL = new GeradorURL();
  20. MysqlConnectionPool mysqlConnectionPool;
  21. private final Connection connection;
  22.  
  23. public UsuarioDAO() throws SQLException {
  24. this.connection = new MysqlConnectionPool().getConnection();
  25. }
  26.  
  27. public List<UsuarioDTO> seleciona() throws SQLException {
  28. List<UsuarioDTO> results = new ArrayList<>();
  29. String sql = "select aqui";
  30. try (PreparedStatement stmt = connection.prepareStatement(sql);
  31. ResultSet resultSet = stmt.executeQuery()) {
  32.  
  33. while (resultSet.next()) {
  34. results.add(populaConta(resultSet));
  35. }
  36. resultSet.close();
  37. stmt.close();
  38. } catch (SQLException e) {
  39. capturaException.ExceptionHandlerController(e);
  40. throw new RuntimeException(e);
  41. } finally {
  42. connection.close();
  43. }
  44. return results;
  45. }}
  46.  
  47. 02-Jan-2018 15:49:16.027 SEVERE [http-nio-8084-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/Head2Head] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.] with root cause
  48. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Add Comment
Please, Sign In to add comment