Guest User

Untitled

a guest
Jun 20th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.sql.*;
  2. import oracle.jdbc.pool.OracleDataSource;
  3. import oracle.jdbc.*;
  4.  
  5. public class EmpSearch
  6. {
  7.  
  8. public static void main (String args[]) throws SQLException
  9. {
  10. // check whether there are two command-line arguments before proceeding
  11. if ( args.length < 2)
  12. {
  13. System.out.println("Enter both a first and last name as command-line arguments.");
  14. System.out.println("You can enter a complete name or an initial substring.");
  15. System.out.println("For example: java EmpSearch j doe");
  16. }
  17. else
  18. {
  19. // connect to a local XE database as user HR
  20. OracleDataSource ods = new OracleDataSource();
  21. ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
  22. Connection conn = ods.getConnection();
  23.  
  24. // call the PL/SQL procedures with the three parameters
  25. // the first two string parameters (1 and 2) are passed to the procedure
  26. // as command-line arguments
  27. // the REF CURSOR parameter (3) is returned from the procedure
  28. String jobquery = "begin get_emp_info(?, ?, ?); end;";
  29. CallableStatement callStmt = conn.prepareCall(jobquery);
  30. callStmt.registerOutParameter(3, OracleTypes.CURSOR);
  31. callStmt.setString(1, args[0]);
  32. callStmt.setString(2, args[1]);
  33. callStmt.execute();
  34.  
  35. // return the result set
  36. ResultSet rset = (ResultSet)callStmt.getObject(3);
  37.  
  38. // determine the number of columns in each row of the result set
  39. ResultSetMetaData rsetMeta = rset.getMetaData();
  40. int count = rsetMeta.getColumnCount();
  41.  
  42. // print the results, all the columns in each row
  43. while (rset.next()) {
  44. String rsetRow = "";
  45. for (int i=1; i<=count; i++){
  46. rsetRow = rsetRow + " " + rset.getString(i);
  47. }
  48. System.out.println(rsetRow);
  49. }
  50.  
  51. }
  52. }
  53. }
  54.  
  55. SimpleJdbcCall call = new SimpleJdbcCall(new JdbcTemplate(getDataSource())).withCatalogName("Owner"."PackageName").withFuctionName("Store Procedure Name");
  56. SqlParameterSource paramMap = new MapSqlParameterSource()
  57. .addValue("attribute1", attribute1.getId())
  58. .addValue("attribute2", Date.valueOf(LocalDate.now()));
  59.  
  60. Long executionId = call.executeFunction(BigDecimal.class, paramMap).longValue();
Add Comment
Please, Sign In to add comment