Run Stored Procedure from JAVA program and see the output
package com.qa.conf;
import java.io.*;
import java.sql.*;
import
java.time.LocalDateTime;
import
java.time.ZonedDateTime;
public class
DBConnection {
public static void main(String
args[]){
System.out.println("Started");
String OPTSCHK= "INTERNAL",
CHASEMEDIUM= "EMAIL",
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@SERVERNAME:PORT/SERVICENAME","tc1","tc1");
//step3 create the statement
object
Statement stmt=con.createStatement();
String insertStoreProc = "{call
TESTPROC1(?,?,?,?)}";
//Create Proc Statement
CallableStatement callableStatement = con.prepareCall(insertStoreProc);
//Add Values to the Input Param
callableStatement.setString(1, OPTSCHK);
callableStatement.setString(2,
CHASEMEDIUM);
//Make Output result sets ready
callableStatement.registerOutParameter(3,
Types.VARCHAR);
callableStatement.registerOutParameter(4,
Types.VARCHAR);
//Execute the Proc Call
callableStatement.executeUpdate();
//Save the Output
String TXN_PROC_ID = callableStatement.getString(3);
String
ResultSet = callableStatement.getString(4);
System.out.println(ResultSet);
System.out.println("TXN_PROC_ID
: "+TXN_PROC_ID);
//close connection
con.close();
}catch(Exception e){
System.out.println(e);
}
}
}
Comments
Post a Comment