ResultSet/Statement close()

Has anybody had any problems with using close() method for Statement and ResultSet objects?

I've got a simple piece of code that creates connection (SQL Server 2000), statement, runs simple query (select * from table_name). It returns me results, but when I try to close my ResultSet object and/or Statement object app just buzzes and I have to close it manually. close() Connection works fine.

Any suggestion on why this can happen?

[455 byte] By [causea] at [2007-11-27 10:24:31]
# 1

"buzzes"? I don't remember seeing that exception.

I don't know what "try to close" looks like, either.

I put the close methods for Connection, Statement, and ResultSet in a helper class, like this:

public class DatabaseUtils

{

public static void close(Connection c)

{

try

{

if (c != null)

{

c.close();

}

}

catch (SQLException e)

{

// log or do something smart here; don't rethrow.

}

}

// Similar for others.

}

I call it like this:

Connection c = null;

try

{

// do some JDBC stuff.

}

catch (Exception e)

{

// handle here

}

finally

{

DatabaseUtils.close(c);

}

Close resources in the narrowest scope possible. Connections are at transaction scope; Statement and ResultSet are local to DAO methods.

%

duffymoa at 2007-7-28 17:28:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Credit to jverd - he's the first person I saw who used those static methods.

%

duffymoa at 2007-7-28 17:28:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...