Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exhausted Resultset

 
Alex George
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I do have the following table called mass_price

>desc mass_price

Name Null Type
------------------------------ -------- -------------------
PRICE_ID NUMBER
ORDER_ID VARCHAR2(40)
PRICE NUMBER(19,7)
RESPONSE VARCHAR2(4000)

>select price_id, order_id, price from mass_price order by price_id asc

PRICE_ID ORDER_ID PRICE
---------------------- ---------------------------------------- ----------------------
1 12090001 100
2 12100001aa 101
3 12100001 101


I do have the following piece of code to access some rows and do some processing

.........
.........
.........

String priceId;
String orderId;
String price;

try {
Connection connection = DriverManager.getConnection(oracleURL, username, password);
Statement selectStatement = connection.createStatement();
String query = "select price_id, order_id, price from mass_price order by price_id asc";
ResultSet resultset = selectStatement.executeQuery(query);


while ( resultset.next() ){

System.out.println( "price_id: "+resultset.getString("price_id") ) ;
System.out.println( "order_id: "+resultset.getString("order_id") ) ;
System.out.println( "price: "+resultset.getString("price") ) ;

priceId = resultset.getString("price_id");
orderId= resultset.getString("order_id");
price = resultset.getString("price");

try {

.......
.......


}catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}// while loop

connection.close();


} catch (SQLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}



I am getting
java.sql.SQLException: Exhausted Resultset

at line
System.out.println( "price_id: "+resultset.getString("price_id") ) ;

Can somebody help me to find out why?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please provide full stack trace.. (exception)

 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some JDBC drivers which only allow you to read a column once from a row. (Note that you're reading each of the columns twice in your code.) Or perhaps it's that they require you to read the columns in order... anyway, just change your code to read each of the columns, once, into a variable. That should make the error go away (and make the code a little easier to read too).
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:There are some JDBC drivers which only allow you to read a column once from a row.


The same point was blinking in my mind but I wasn't sure.

Thanks Paul..

 
Alex George
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seems to be working.
Thanks to everybody.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic