PDA

View Full Version : java.sql.SQLException: Exhausted Resultset


Phi
03-19-2005, 08:13 PM
Hi all,
This is the code which i use to test connecting to Oracle db.
But it says "Exhausted Resultset"

System.out.println("Connecting...");
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:@" + database, user, password);

Statement stmt = conn.createStatement();

ResultSet rset = stmt.executeQuery ("SELECT id,name FROM pmain");

System.out.println(rset.findColumn("Name"));
rset.next();
System.out.println(rset.getString(1));
// close the result set, the statement and connect
rset.close();
stmt.close();
conn.close();
System.out.println("Your JDBC installation is correct.");

pmain has two rows.

ID NAME
---------- ---------------------------------------------------------------------
1 Phi
2 Tram
Please give a look and help me to fix this funny bug.
Cheer,
Phi.

Faroch Hordil
03-20-2005, 04:13 AM
You are using the Oracle driver. Have you registered it?

If not, put this before your attempt at getting a connection objekt

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Fred



"Phi" <nnphi2304@gmail.com> wrote in message
news:a8dcada7.0503192013.775ffe67@posting.google.com... Hi all, This is the code which i use to test connecting to Oracle db. But it says "Exhausted Resultset" System.out.println("Connecting..."); Connection conn = DriverManager.getConnection ("jdbc:oracle:oci:@" + database, user, password); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery ("SELECT id,name FROM pmain"); System.out.println(rset.findColumn("Name")); rset.next(); System.out.println(rset.getString(1)); // close the result set, the statement and connect rset.close(); stmt.close(); conn.close(); System.out.println("Your JDBC installation is correct."); pmain has two rows. ID NAME ---------- --------------------------------------------------------------------- 1 Phi 2 Tram Please give a look and help me to fix this funny bug. Cheer, Phi.

Malcolm Dew-Jones
03-20-2005, 10:56 AM
Phi (nnphi2304@gmail.com) wrote:
: Hi all,
: This is the code which i use to test connecting to Oracle db.
: But it says "Exhausted Resultset"

i'm thinking the connection involves a long round trip, and has to compete
with a lot of other traffic on the route

--

This space not for rent.

Rauf Sarwar
03-22-2005, 02:01 AM
Your code is not very well written. Please read java docs and learn the
functions in a given class. My comments are embedded.


Phi wrote: Hi all, This is the code which i use to test connecting to Oracle db. But it says "Exhausted Resultset" System.out.println("Connecting...");

Need to register the driver here as pointed out by someone else before
opening a connection. See DriverManager.registerDriver
Connection conn = DriverManager.getConnection ("jdbc:oracle:oci:@" + database, user,
password); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery ("SELECT id,name FROM
pmain"); System.out.println(rset.findColumn("Name"));

Why do you have this above statement here? It's redundant unless you
just want to print the column index. It can be used in the next
System.out call to pass the column index e.g.
System.out.println(rset.getString(rset.findColumn("Name"));
rset.next();

You are not testing the return boolean value from call to next before
trying to fetch from it. This is the error you are receiving that the
resultset does not have any rows. Generally you put the call to next in
a loop e.g.
while(rset.next()) {
// It ONLY gets here if there are rows
System.out.println(rset.getString(2));
}
OR
test the return value from rset.next()... true/false before calling
rset.getxxxx();
System.out.println(rset.getString(1));

Here, you are passing the column index as 1 but most likely you are
looking for the Name value. Resultset columns go as 1, 2, 3 and so on.
If you are looking for ID then use 1... use 2 for Name.
// close the result set, the statement and connect rset.close(); stmt.close(); conn.close(); System.out.println("Your JDBC installation is correct."); pmain has two rows. ID NAME ----------
--------------------------------------------------------------------- 1 Phi 2 Tram Please give a look and help me to fix this funny bug. Cheer, Phi.

Regards
/Rauf


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service