|
|
|
|
|
|
| Author |
Message |
Phi *nix forums beginner
Joined: 20 Mar 2005
Posts: 2
|
Posted: Sun Mar 20, 2005 3:13 am Post subject:
java.sql.SQLException: Exhausted Resultset
|
|
|
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
|
Posted: Sun Mar 20, 2005 11:13 am Post subject:
Re: java.sql.SQLException: Exhausted Resultset
|
|
|
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
|
Posted: Sun Mar 20, 2005 5:56 pm Post subject:
Re: java.sql.SQLException: Exhausted Resultset
|
|
|
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
|
Posted: Tue Mar 22, 2005 9:01 am Post subject:
Re: java.sql.SQLException: Exhausted Resultset
|
|
|
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"));
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 |
|
 |
|
|
The time now is Thu Jan 08, 2009 1:59 am | All times are GMT
|
|
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
|
|