We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


JDBC Error: ResultSet object has been closed — Vertica Forum

JDBC Error: ResultSet object has been closed

When I am executing a ResultSet.next(), I am getting the error ResultSet object has been closed. This is even happening within the loop processing the ResultSet. The loop executes the .next() but the first call to get a result returns the error. I am getting pretty small datasets, typically less than 10 records, just a pair of longs.

 

The maddening part of this is that with identical inputs, I only see the error about 10% of the time. Seems like a problem between the database and the app server, but I am not 100% sure.

 

I'm hoping someone can point out where I have gone wrong or what I could do to mitigate the problem.

 

public Map<Long, Long> getUsersForBeacons(List<Long> beaconIds) throws DbException {

StringBuilder sql = new StringBuilder();
sql.append("select beacon_id, participant_id from participant where beacon_id in (");

int count = beaconIds.size();

for (int i = 0; i < count - 1; i++) {
sql.append("?,");
}

sql.append("?)");

checkConnection();

try {
PreparedStatement statement = mConn.prepareStatement(sql.toString());

for (int i = 0; i < count; i++) {
statement.setLong(i + 1, beaconIds.get(i));
}

Map<Long, Long> result = new HashMap<>();

long tempBeaconId;
long tempParticipantId;

ResultSet rows = statement.executeQuery();

while (rows.next()) {
if(!rows.isClosed()) {

tempBeaconId = rows.getLong("beacon_id");
tempParticipantId = rows.getLong("participant_id");

if(tempBeaconId > 0 && tempParticipantId > 0) {
result.put(tempBeaconId, tempParticipantId);
}

} else {
//This definitely happens
LOG.warn("ResultSet closed during loop");
}
}

rows.close();

if (!statement.isClosed()) {
statement.close();
}

return result;
} catch (SQLException e) {
LOG.error(e.getStackTrace());
LOG.error("getUsersForBeacons database error", e);
throw new DbException(e);
}
}

private void checkConnection() throws DbException {

try {
if (mConn == null || mConn.isClosed()) {
mConn = mDataSource.getConnection();
}
} catch (SQLException ex) {
throw new DbException(ex);
}
}

Comments

  • Hi,

     

    Could you tell me the versions of the following that you're seeing this problem with?

    • HP Vertica
    • JDBC driver
    • Java

    Thanks!

     

     

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file