This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sqlException-ResultSet Invalidated!

 
Pat Breen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic