Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace package test_system is
- type ref_cursor is ref cursor;
- procedure demo_show_students(p_gpa IN STUDENTS.gpa%TYPE,p_ref_cursor OUT ref_cursor );
- end test_system;
- /
- create or replace package body test_system is
- procedure demo_show_students(p_gpa IN STUDENTS.gpa%TYPE,p_ref_cursor OUT ref_cursor )
- is
- v_sql_str varchar2(4000);
- begin
- v_sql_str:='select sid,firstname,lastname,status,gpa,email from students where gpa = p_gpa';
- open p_ref_cursor for v_sql_str;
- end demo_show_students;
- end test_system;
- import java.sql.*;
- import oracle.jdbc.OracleTypes;
- public class ShowStudents {
- public void showStudents() {
- try {
- // Connection to Oracle server
- OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();
- ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
- Connection conn = ds.getConnection("*****", "*****");
- String val = '4'+"";
- CallableStatement cs = conn.prepareCall("{call
- test_system.demo_show_students(?,?)}");
- cs.setString(1, val);
- cs.registerOutParameter(2, OracleTypes.CURSOR);
- cs.execute();
- ResultSet rs = (ResultSet)cs.getObject(2);
- while (rs.next()) {
- System.out.println(rs.getString(1) + "t" +
- rs.getString(2) + "t" + rs.getString(3) +
- rs.getString(4) +
- "t" + rs.getDouble(5) + "t" +
- rs.getString(6));
- }
- cs.close();
- } catch (SQLException ex) {
- System.out.println("n*** SQLException caught ***n");
- ex.printStackTrace();
- } catch (Exception e) {
- System.out.println("n*** other Exception caught ***n");
- }
- }
- }
- Exception :
- *** SQLException caught ***
- ORA-00904: "P_GPA": invalid identifier
- ORA-06512: at "PROJECT2.TEST_SYSTEM", line 7
- ORA-06512: at line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement