f



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.
0
nnphi2304
3/20/2005 4:13:57 AM
comp.databases.oracle.tools 4963 articles. 0 followers. art (172) is leader. Post Follow

3 Replies
616 Views

Similar Articles

[PageSpeed] 33

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. 


0
Faroch
3/20/2005 12:13:15 PM
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.
0
yf110
3/20/2005 6:56:58 PM
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

0
Rauf
3/22/2005 10:01:05 AM
Reply: