Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. create or replace package Proj2_student_reg_package is
  2. type data_cursor is ref cursor;
  3.  
  4. procedure add_students(sidIn IN students.sid%type, fnameIn IN students.firstname%type,
  5. lnameIn IN students.lastname%type, statusIn IN students.status%type,
  6. gpaIn IN students.gpa%type, emailIn IN students.gpa%type,
  7. ret_message OUT varchar2);
  8.  
  9. end Proj2_student_reg_package;
  10. /
  11.  
  12. create or replace package body Proj2_student_reg_package as
  13.  
  14. procedure add_students(sidIn IN students.sid%type, fnameIn IN students.firstname%type,
  15. lnameIn IN students.lastname%type, statusIn IN students.status%type,
  16. gpaIn IN students.gpa%type, emailIn IN students.gpa%type,
  17. ret_message OUT varchar2)
  18. is
  19. begin
  20. insert into students values(sidIn ,fnameIn,lnameIn,statusIn,gpaIn,emailIn);
  21. COMMIT;
  22. ret_message := 'Success';
  23.  
  24. EXCEPTION
  25. WHEN OTHERS THEN
  26. ret_message := 'Error';
  27. end add_students;
  28.  
  29.  
  30.  
  31.  
  32. end Proj2_student_reg_package;
  33.  
  34. import java.sql.CallableStatement;
  35. import java.sql.Connection;
  36. import java.sql.SQLException;
  37. import java.sql.Types;
  38. import java.util.Scanner;
  39.  
  40. import oracle.jdbc.OracleTypes;
  41. import oracle.jdbc.pool.OracleDataSource;
  42.  
  43. public class AddStudent {
  44. public void addStudent(){
  45. Scanner line = new Scanner(System.in);
  46. try
  47. {
  48.  
  49. //Connection to Oracle server
  50. OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();
  51. ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
  52. Connection conn = ds.getConnection("*****", "****");
  53.  
  54. System.out.print("Enter the sid: ");
  55. String sid = line.next();
  56. System.out.print("Enter first name: ");
  57. String fname = line.next();
  58. System.out.print("Enter last name: ");
  59. String lname = line.next();
  60. System.out.print("Enter status: ");
  61. String status = line.next();
  62. System.out.print("Enter gpa: ");
  63. String gpa = line.next();
  64. System.out.print("Enter email: ");
  65. String email = line.next();
  66.  
  67.  
  68. CallableStatement cs = conn.prepareCall("{call Proj2_student_reg_package.add_students(?,?,?,?,?,?,?)}");
  69.  
  70. cs.setString(1, sid);
  71. cs.setString(2, fname);
  72. cs.setString(3, lname);
  73. cs.setString(4, status);
  74. cs.setString(5, gpa);
  75. cs.setString(6, email);
  76. cs.registerOutParameter(7, Types.VARCHAR);
  77.  
  78. cs.executeQuery();
  79. System.out.println(cs.getString(7));
  80. cs.close();
  81. //line.close();
  82. }
  83. catch (SQLException e) { System.out.println("SQLException " + e.getMessage());}
  84. catch (Exception e) {System.out.println(e);}
  85. }
  86.  
  87. }
  88.  
  89. create table students (sid char(4) primary key check (sid like 'B%'),
  90. firstname varchar2(15) not null, lastname varchar2(15) not null, status varchar2(10)
  91. check (status in ('freshman', 'sophomore', 'junior', 'senior', 'graduate')),
  92. gpa number(3,2) check (gpa between 0 and 4.0), email varchar2(20) unique);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement