wood burning stoves 2.0*
The moose likes JDBC and the fly likes Nested Reslutsets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Nested Reslutsets" Watch "Nested Reslutsets" New topic

Nested Reslutsets

Geethandh K

Joined: Aug 17, 2001
Posts: 2
Please help me. Cen we execute a resultset in another resultset? the sample code is here.
import java.sql.*;
class Employee
public static void main (String args []) throws SQLException
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc racle:thin:@ rcl","scott", "tiger");
Statement stmt = conn.createStatement ();
Statement stmt1 = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select empno, ename from emp");
while (rset.next ())
int eno = rset.getInt(1);
String enm = rset.getString(2);
System.out.println (eno+"----"+enm);
ResultSet rs = stmt1.executeQuery("select sal from emp where empno = "+eno);
System.out.println (rs.getInt(1));
catch(Exception e)
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

when you compiled it and ran it, did it work? If not, what is the error message?
one error is this:

you have to call the method rs.next() before you can read the first record of rs.

Geethandh K

Joined: Aug 17, 2001
Posts: 2
Thank you very much Mr.Jamie. It worked well.
Don't get me started about those stupid light bulbs.
subject: Nested Reslutsets
Similar Threads
can't update database?
what is sqlj?
strange error while executing an insert statement in MS SQL Server
Classes12.zip Thin Drivers
JDBC and MS Access