permaculture playing cards*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Nested Reslutsets" Watch "Nested Reslutsets" New topic
Author

Nested Reslutsets

Geethandh K
Greenhorn

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
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc racle:thin:@127.0.0.1:1521 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)
{
System.out.println(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.

Jamie
Geethandh K
Greenhorn

Joined: Aug 17, 2001
Posts: 2
Thank you very much Mr.Jamie. It worked well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested Reslutsets