File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes sqlException-ResultSet Invalidated! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sqlException-ResultSet Invalidated!" Watch "sqlException-ResultSet Invalidated!" New topic

sqlException-ResultSet Invalidated!

Pat Breen

Joined: Nov 08, 2003
Posts: 5
Here is the very sloppy code...
result = stmt.executeQuery(request);

// The following statement checks if query successful
while ( {

symbol = result.getString(1);
System.out.println("symbol = " + symbol);

quantity = result.getInt(2);
System.out.println("quantity = " + quantity);
newRequest = "SELECT price FROM Stock "
+ " WHERE symbol=" + "'" + symbol + "'";
nestedResult = nestedStmt.executeQuery(newRequest);
price = nestedResult.getFloat(1);
System.out.println("price======" + price);
}//end nested while
}//end while
shares.add(new Share(new Stock(symbol,price),quantity));
//cust = this.getCustomer(id);
port = new Portfolio(cust,shares);
/*else {
// if query failed
throw new BrokerException("Record for " + id +
" not found");
} */
// return portfolio
return port;
} catch (SQLException e) {
throw new BrokerException("BrokerDbImpl.getCustomer\n" +e);
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

It would be helpful to those of us in the peanut gallery if you included:
- an indication as to what line the exception takes place
- the exception, including the stack trace
- the database and driver you are using
- the code which creates both the Statement objects used in your code snipped
My wild-assed guess is that the second query invalidates the results of the first query, but that's dependent on the information above.

[How To Ask Questions On JavaRanch]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Pat, also be sure to enclose any code or stack trace samples in UBB code tags. Most readers here, myself included, will not read unformatted code. It's just too hard and takes too long.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: sqlException-ResultSet Invalidated!
It's not a secret anymore!