Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE function CUSTOMERAPP.procOneParameter
- return boolean
- IS
- BEGIN
- return true;
- END;
- public class CallFunctionFromOracle {
- public static void main(String... arg) throws SQLException {
- Connection con = null;
- CallableStatement callableStmt = null;
- try {
- // registering Oracle driver class
- Class.forName("oracle.jdbc.driver.OracleDriver");
- // getting connection
- con = DriverManager.getConnection(
- "jdbc:oracle:thin:@10.11.201.166:1521:xe", "customerapp", "customerapp");
- System.out.println("Connection established successfully!");
- callableStmt = con.prepareCall("{ ? = call procOneParameter()}");
- //Database function will return value as OUT parameter
- callableStmt.registerOutParameter(1, java.sql.Types.NUMERIC);
- //IN parameter -
- //set methods are used for setting IN parameter values of Stored procedure
- // callableStmt.setInt(2, 11);
- //Execute database Function,
- callableStmt.execute();
- // Then retrieve values returned by method using using get methods.
- System.out.println("salary = " + callableStmt.getBoolean(1));
- System.out.println("Function executed successfully, "
- + "salary has been fetched from Employee table");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- finally{
- try {
- if(callableStmt!=null) callableStmt.close(); //close CallableStatement
- if(con!=null) con.close(); // close connection
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- java.sql.SQLException: ORA-06550: line 1, column 13:
- PLS-00382: expression is of wrong type
- ORA-06550: line 1, column 7:
- PL/SQL: Statement ignored
- at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
- at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
- at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
- at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
- at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
- at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
- at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:204)
- at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1007)
- at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
- at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
- at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3677)
- at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4714)
- at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
- at callfunctionfromoracle.CallFunctionFromOracle.main(CallFunctionFromOracle.java:44)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement