aspose file tools*
The moose likes JDBC and the fly likes Exhausted Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exhausted Resultset" Watch "Exhausted Resultset" New topic
Author

Exhausted Resultset

Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51

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

Joined: Dec 06, 2005
Posts: 1321

please provide full stack trace.. (exception)


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Dec 06, 2005
Posts: 1321

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

Joined: Mar 23, 2007
Posts: 51
That seems to be working.
Thanks to everybody.
 
 
subject: Exhausted Resultset