niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle » Tools
java.sql.SQLException: Exhausted Resultset
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Phi
*nix forums beginner


Joined: 20 Mar 2005
Posts: 2

PostPosted: Sun Mar 20, 2005 3:13 am    Post subject: java.sql.SQLException: Exhausted Resultset Reply with quote

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.
Back to top
Faroch Hordil
*nix forums beginner


Joined: 11 Mar 2005
Posts: 6

PostPosted: Sun Mar 20, 2005 11:13 am    Post subject: Re: java.sql.SQLException: Exhausted Resultset Reply with quote

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...
Quote:
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.
Back to top
Malcolm Dew-Jones
*nix forums Guru


Joined: 04 Mar 2005
Posts: 418

PostPosted: Sun Mar 20, 2005 5:56 pm    Post subject: Re: java.sql.SQLException: Exhausted Resultset Reply with quote

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.
Back to top
Rauf Sarwar
*nix forums Guru


Joined: 03 May 2005
Posts: 353

PostPosted: Tue Mar 22, 2005 9:01 am    Post subject: Re: java.sql.SQLException: Exhausted Resultset Reply with quote

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:
Quote:
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

Quote:
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"));

Quote:
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();

Quote:
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.

Quote:
// 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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 1:59 am | All times are GMT
navigation Forum index » Databases » Oracle » Tools
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before... Shaguf Apache 0 Tue Dec 23, 2008 7:41 am
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Is there C/C++ corresponding function in Linux for Java's... xiebopublic@gmail.com apps 4 Fri Jul 21, 2006 3:22 am
No new posts Is there C/C++ corresponding function in Linux for Java's... xiebopublic@gmail.com C++ 1 Fri Jul 21, 2006 2:44 am
No new posts Using python code from Java? fortepianissimo python 4 Thu Jul 20, 2006 5:36 pm

Credit Card | Credit Card | Novela romantica | Credit Cards | Proxy
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1844s ][ Queries: 16 (0.0957s) ][ GZIP on - Debug on ]