eclair icon indicating copy to clipboard operation
eclair copied to clipboard

All DB Statement and ResultSet should be closed when no longer needed

Open DerEwige opened this issue 3 years ago • 0 comments

I went through the code and to my surpise you don't close any Statement or ResultSet after use.

Afaik this is bad practice and can lead to degraded DB performance and resource leakes (if combined with bad JDBCD driver)

Simple example from: CompareDb.scala

A close() statement after the while(rs.next()) loop would immediately free up the resources

    val rs1 = conn1.prepareStatement(s"SELECT * FROM $table1").executeQuery()
    val rs2 = conn2.prepareStatement(s"SELECT * FROM $table2").executeQuery()

    var hashes1 = List.empty[ByteVector]
    while (rs1.next()) {
      hashes1 = hash1(rs1) +: hashes1
    }
    rs1.close() 

    var hashes2 = List.empty[ByteVector]
    while (rs2.next()) {
      hashes2 = hash2(rs2) +: hashes2
    }
    rs2.close()

DerEwige avatar Sep 20 '22 09:09 DerEwige