permaculture playing cards*
The moose likes JDBC and the fly likes sqlException-ResultSet Invalidated! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sqlException-ResultSet Invalidated!" Watch "sqlException-ResultSet Invalidated!" New topic
Author

sqlException-ResultSet Invalidated!

Pat Breen
Greenhorn

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

// The following statement checks if query successful
while (result.next()) {
System.out.println("-----------------------2-----------------------");

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);
while(nestedResult.next()){
price = nestedResult.getFloat(1);
System.out.println("price======" + price);
}//end nested while
nestedResult.close();
}//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) {
e.printStackTrace();
throw new BrokerException("BrokerDbImpl.getCustomer\n" +e);
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

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.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sqlException-ResultSet Invalidated!
 
Similar Threads
Shopping cart help
returning an int
Could not locate DB driver
data mismatch error
Null data issue