question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Solved, pending release]: Close java.sql.ResultSet objects used in the DB implementations

See original GitHub issue

Currently ResultSet objects have not been closed in our DB implementations, they need to be closed to avoid memory leaks.

example :

public static KeyValueInfo getKeyValue(Start start, String key) throws SQLException, StorageQueryException {
    String QUERY = "SELECT value, created_at_time FROM " + Config.getConfig(start).getKeyValueTable()
            + " WHERE name = ?";

    try (Connection con = ConnectionPool.getConnection(start);
            PreparedStatement pst = con.prepareStatement(QUERY)) {
        pst.setString(1, key);
        ResultSet result = pst.executeQuery();
        if (result.next()) {
            return KeyValueInfoRowMapper.getInstance().mapOrThrow(result);
        }
    }
    return null;
}

Result set interface looks like this :

public interface ResultSet extends Wrapper, AutoCloseable

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
rishabhpoddarcommented, Feb 17, 2022

Thanks @anugrahsinghal for resolving this issue.

I have added your profile to the contributor’s list in the core’s readme. Since these are refactor changes, they will be released in the next change to the core. Keeping this issue open until then.

1reaction
anugrahsinghalcommented, Feb 16, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Must JDBC Resultsets and Statements be closed separately ...
Per JDBC specs closing any higher object will automatically close lower objects. Closing Connection will close any Statement s that connection has created....
Read more >
Closing Connection Does Not Close Statement And ResultSet
I tried a different database and driver (MySQL) and verified that the MySQL JDBC driver DOES close these two objects once the connection...
Read more >
ResultSet (Java Platform SE 7 ) - Oracle Help Center
Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.
Read more >
Jaybird JDBC Driver Java Programmer's Manual
This manual covers Jaybird 4 and may use Java 8 and Firebird 3.0 specific features, but most examples and information also apply to...
Read more >
Features - H2 Database Engine
Compatibility modes for IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL. Security Features. Includes a solution for the SQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found