Take the 2-minute tour ×

I want to test the connection so I am using the query: 'SELECT 1 FROM dual' to compare the value returned.

ResultSet rs = stmt.executeQuery("SELECT 1 FROM dual");

on doing rs.next() the exception thrown is:

java.sql.SQLException: Closed Connection: next

How can I get rs.getString(1) as 1 by executing the query?

share|improve this question
I don't understand what you're trying to do: if the connection is closed then you can't get the next(), if the connection is opened then why do you need the value 1 ? –  A.B.Cade Mar 27 '12 at 14:08
add comment

1 Answer

You cannot compare the value returned when checking the connection:
If the connection is closed then you get no results, more then that, you won't be able to even create the statement ...

In your code you might have the connection closed somewhere before the rs.next() command.

you can see here a post similar to what you need

share|improve this answer
add comment

Your Answer


