• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Reslutsets

 
Geethandh K
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Mr.Jamie. It worked well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic