JDBC problem & 7.1

Started by Loïc Courtoisalmost 25 years ago1 messagesgeneral
Jump to latest
#1Loïc Courtois
lcourtois@netpartage.fr

Hello,

I have the following java source code:

This one work with pg 7.0.3 , but not with 7.1, with the following error
message:

java.lang.NullPointerException
at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:116)
at ouah.stats.Stats.go(Stats.java:242)
at daily.main(daily.java:54)

///////////////////////////////////////BEGIN////////////////////////////////
///:
Statement statement;
ResultSet results, results2;

try {
statement = conn.createStatement();

if(statement.execute("SELECT ...")) {
results = statement.getResultSet();
while(results.next()) {
System.out.println(results.getInt("nb"));

if(statement.execute("SELECT ... WHERE no = " +
results.getString("no") ... ")) {
results2 = statement.getResultSet();
while(results2.next()) {
System.out.println("\t" +
results2.getInt("nb"));
}
results2.close();
}
}
results.close();
statement.close();
}
} catch (java.sql.SQLException e) { e.printStackTrace();}
///////////////////////////////////////END//////////////////////////////////
/:

This one work with pg 7.1
///////////////////////////////////////BEGIN////////////////////////////////
///:
Statement statement, s2;
ResultSet results, results2;

try {
statement = conn.createStatement();
s2 = conn.createStatement();

if(statement.execute("SELECT ...")) {
results = statement.getResultSet();
while(results.next()) {
System.out.println(results.getInt("nb"));

if(s2.execute("SELECT ... WHERE no = " +
results.getString("no") ... ")) {
results2 = s2.getResultSet();
while(results2.next()) {
System.out.println("\t" +
results2.getInt("nb"));
}
results2.close();
}
}
results.close();
statement.close();
s2.close();
}
} catch (java.sql.SQLException e) { e.printStackTrace();}
///////////////////////////////////////END//////////////////////////////////
/:

Please, could I have advice?

Thanks!!

Loic Courtois
Netpartage