Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import oracle.jdbc.pool.OracleDataSource;
- import oracle.jdbc.*;
- public class EmpSearch
- {
- public static void main (String args[]) throws SQLException
- {
- // check whether there are two command-line arguments before proceeding
- if ( args.length < 2)
- {
- System.out.println("Enter both a first and last name as command-line arguments.");
- System.out.println("You can enter a complete name or an initial substring.");
- System.out.println("For example: java EmpSearch j doe");
- }
- else
- {
- // connect to a local XE database as user HR
- OracleDataSource ods = new OracleDataSource();
- ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
- Connection conn = ods.getConnection();
- // call the PL/SQL procedures with the three parameters
- // the first two string parameters (1 and 2) are passed to the procedure
- // as command-line arguments
- // the REF CURSOR parameter (3) is returned from the procedure
- String jobquery = "begin get_emp_info(?, ?, ?); end;";
- CallableStatement callStmt = conn.prepareCall(jobquery);
- callStmt.registerOutParameter(3, OracleTypes.CURSOR);
- callStmt.setString(1, args[0]);
- callStmt.setString(2, args[1]);
- callStmt.execute();
- // return the result set
- ResultSet rset = (ResultSet)callStmt.getObject(3);
- // determine the number of columns in each row of the result set
- ResultSetMetaData rsetMeta = rset.getMetaData();
- int count = rsetMeta.getColumnCount();
- // print the results, all the columns in each row
- while (rset.next()) {
- String rsetRow = "";
- for (int i=1; i<=count; i++){
- rsetRow = rsetRow + " " + rset.getString(i);
- }
- System.out.println(rsetRow);
- }
- }
- }
- }
- SimpleJdbcCall call = new SimpleJdbcCall(new JdbcTemplate(getDataSource())).withCatalogName("Owner"."PackageName").withFuctionName("Store Procedure Name");
- SqlParameterSource paramMap = new MapSqlParameterSource()
- .addValue("attribute1", attribute1.getId())
- .addValue("attribute2", Date.valueOf(LocalDate.now()));
- Long executionId = call.executeFunction(BigDecimal.class, paramMap).longValue();
Add Comment
Please, Sign In to add comment