1

I am using derby for database. and my normal insert/update operation is working fine. But some times while insert query I am getting "No Current Connect" error message.

I searched about it but not found proper solution.

Do any one knows why this exception occurred ?

Thanks

Tej

Tej Kiran
  • 2,218
  • 5
  • 21
  • 42

1 Answers1

0

its caused when you are trying to execute operations on a closed connection object. So you need to check if the connection is closed, if so ..then connect again:-

public Connection getConnection() throws SQLException {
    if(connection==null || connection.isClosed()) {
        connect();
    }
    return connection;
}

private void connect() throws SQLException {
    try {
        connection = DriverManager.getConnection(DBURL);
        logger.info("database connection established");
    } catch (SQLException e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Varun
  • 89
  • 6