Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: What way is right to invok ResultSet form JavaBean in Servlet?


Message #1 by "billczwen" <billczwen@e...> on Tue, 29 Oct 2002 03:57:26
oracle's package P_T_Reoprt

		create or replace package P_T_Reoprt
		as
		type v_cursor is ref cursor; 
		function T_Reoprt (j varchar2) return v_cursor; 
		end P_T_Reoprt;

		create or replace package body P_T_Reoprt
		as
		function T_Reoprt (j varchar2) return v_cursor 
		is
		rc v_cursor;
		begin
		  open rc for select * from customer where customer.sex 
= j;
		  return rc;
		end;
		end P_T_Reoprt;

------------------------------------------------

DBConnection.java(a method of the javabean's source)
....
  public ResultSet executeProduce(){
    rs = null;
    try {
    //connect the database
    conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.0.176:1521:yzttest","bill","bill");
    System.out.println("004:connection success!");
    // Prepare a PL/SQL call
    CallableStatement call =  conn.prepareCall ("{?=call 
P_T_Reoprt.T_Reoprt(?)}");
    System.out.println("005:prepare PL/SQL Call success!");
    // Find out all Record
    call.registerOutParameter (1,OracleTypes.CURSOR);
    call.setString (2,"M");
    System.out.println("006:PL/SQL define success !");
    call.execute ();
    System.err.println("007:PL/SQL execute success!");
    ResultSet rs = (ResultSet)call.getObject (1);
    System.out.println("008:take resultset success!");
    }
    catch(SQLException ex) {
    System.err.println("012:fail to DBConnection.executeProduce: " + 
ex.getMessage());
    }
    return rs;
  }
....

------------------------------------------------

when i invok that DBConnection's executeProduce method in the Servlet, 
that had happened and error when execute at "while(rs.next())"
...
    DBConnection JavaBean = new DBConnection();
    System.out.println("001:JavaBean instance success!");
    ResultSet rs=JavaBean.executeProduce();
    System.out.println("002:method invok success!");
    while (rs.next())//<<--------------that has error
    System.out.println("018:there have record!");
    System.out.println (rs.getString(1));
    System.out.println("013:return record success!");
...


What way is right to invok ResultSet form JavaBean in Servlet?
My way is error,now?



  Return to Index