Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. create or replace package test_system is
  2. type ref_cursor is ref cursor;
  3. procedure demo_show_students(p_gpa IN STUDENTS.gpa%TYPE,p_ref_cursor OUT ref_cursor );
  4. end test_system;
  5. /
  6.  
  7. create or replace package body test_system is
  8. procedure demo_show_students(p_gpa IN STUDENTS.gpa%TYPE,p_ref_cursor OUT ref_cursor )
  9. is
  10. v_sql_str varchar2(4000);
  11. begin
  12. v_sql_str:='select sid,firstname,lastname,status,gpa,email from students where gpa = p_gpa';
  13. open p_ref_cursor for v_sql_str;
  14. end demo_show_students;
  15. end test_system;
  16.  
  17. import java.sql.*;
  18.  
  19. import oracle.jdbc.OracleTypes;
  20.  
  21. public class ShowStudents {
  22.  
  23. public void showStudents() {
  24.  
  25. try {
  26.  
  27. // Connection to Oracle server
  28. OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();
  29. ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
  30. Connection conn = ds.getConnection("*****", "*****");
  31.  
  32. String val = '4'+"";
  33. CallableStatement cs = conn.prepareCall("{call
  34. test_system.demo_show_students(?,?)}");
  35. cs.setString(1, val);
  36.  
  37. cs.registerOutParameter(2, OracleTypes.CURSOR);
  38. cs.execute();
  39. ResultSet rs = (ResultSet)cs.getObject(2);
  40.  
  41. while (rs.next()) {
  42. System.out.println(rs.getString(1) + "t" +
  43. rs.getString(2) + "t" + rs.getString(3) +
  44. rs.getString(4) +
  45. "t" + rs.getDouble(5) + "t" +
  46. rs.getString(6));
  47. }
  48.  
  49.  
  50. cs.close();
  51.  
  52. } catch (SQLException ex) {
  53. System.out.println("n*** SQLException caught ***n");
  54. ex.printStackTrace();
  55. } catch (Exception e) {
  56. System.out.println("n*** other Exception caught ***n");
  57. }
  58. }
  59. }
  60.  
  61.  
  62.  
  63. Exception :
  64.  
  65. *** SQLException caught ***
  66. ORA-00904: "P_GPA": invalid identifier
  67. ORA-06512: at "PROJECT2.TEST_SYSTEM", line 7
  68. ORA-06512: at line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement