Forum Stats

  • 3,814,139 Users
  • 2,258,824 Discussions
  • 7,892,587 Comments

Discussions

Cannot perform fetch on a PLSQL statement: next

ram7
ram7 Member Posts: 18

Storedprocedure:

create or replace PROCEDURE ADDITION

(

  A IN NUMBER 

, B IN NUMBER 

, C OUT NUMBER 

) AS

BEGIN

  C := A+B;

  dbms_output.put_line(c);

END ADDITION;

JDBC program:

stmt = conn.prepareCall("BEGIN addition(?, ?,?); END;");

      stmt.setInt(1, 10);

      stmt.setInt(2, 85);

      stmt.registerOutParameter(3, java.sql.Types.INTEGER);

      ResultSet rs = stmt.executeQuery();

      while(rs.next()){

      int c =rs.getInt("c");

    System.out.println(c);

      }

 

      stmt.close();

      conn.close();

   }

Error:

java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next

  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)

  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)

  at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:192)

  at stored_procedure.main(stored_procedure.java:32)

Tagged:

Best Answer

Answers

  • ram7
    ram7 Member Posts: 18

    <span class="pln">cstmt </span><span class="pun">=</span><span class="pln"> conn</span><span class="pun">.</span><span class="pln">prepareCall</span><span class="pun">(</span><span class="str" style="color: #800000;">"BEGIN addition(?, ?,?); END;"</span><span class="pun">);</span><span class="pln"><br/>cstmt</span><span class="pun">.</span><span class="pln">setInt</span><span class="pun">(</span><span class="lit" style="color: #800000;">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit" style="color: #800000;">10</span><span class="pun">);</span><span class="pln"><br/>cstmt</span><span class="pun">.</span><span class="pln">setInt</span><span class="pun">(</span><span class="lit" style="color: #800000;">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit" style="color: #800000;">85</span><span class="pun">);</span><span class="pln"><br/>cstmt</span><span class="pun">.</span><span class="pln">registerOutParameter</span><span class="pun">(</span><span class="lit" style="color: #800000;">3</span><span class="pun">,</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="pln">Types</span><span class="pun">.</span><span class="pln">INTEGER</span><span class="pun">);</span><span class="pln"><br/>cstmt</span><span class="pun">.</span><span class="kwd" style="color: #00008b;">execute</span><span class="pun">();</span><span class="pln"><br/>int c </span><span class="pun">=</span><span class="pln"> cstmt</span><span class="pun">.</span><span class="pln">getInt</span><span class="pun">(</span><span class="lit" style="color: #800000;">3</span><span class="pun">);</span><span class="pln"><br/>System</span><span class="pun">.</span><span class="pln">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">c</span><span class="pun">);</span>



    its works perfectly....

    ram7
  • Your procedure is NOT returning a result set.

    It returns a scalar value as an OUT parameter:

    C OUT NUMBER 
This discussion has been closed.