I want to use
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
.
.
.
try (Statement stmt = connection.createStatement()) {
try (ResultSet rset = stmt.executeQuery(url)) {
while (rset.next()) {
System.out.println (rset.getString(1));
}
}
}
in jdk 6. But it says that this is not supported. What can I do?
That’s try-with-resource which is a new feature in Java SE 7. In Java SE 6 (recently had a life extension into next year, but I wouldn’t write new code for it):
You can use the Execute Around idiom to factor out to repetitive bits.