EMPJAVA-Calling Java Stored Procedures
//Title:Using SQLJ with Java Stored Procedures
//giving the employee an increment and changing the employee's location package modify_emp;
import Java.sql.*;
import Java.io.*;
class maintain emp
{
public static void main (String args [])—declaring main function
throws SQLException, IOException
{
String cstring = args[0]; String uname = args[1]; String pwd = args[2];
//Load JDBC Drivers
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver( ) );
// It is connect to the database by using the specified parameters
Conection conn = DriveManager.getConnection (cstring, uname, pwd);
//Prepare to call the stored procedure
CallableStatement cstmt = conn.prepareCall ( " { ? = call modify_emp_update_emp (?, ?, ?, ?) } " ) ;
// We are using positional arguments
cstmt.registerOutParameter (1, Types.INTEGER);--First argument is declared as an OUT parameter
cstmt.setString (2, "SCOTT"); --The second argument is SCOTT
cstmt.setInt (3, 50000); --The third argument is the raise
cstmt.setString (4,"MIAMI");--The fourth argument is the city
cstmt.execute ( ); --Execute the command
int new_salary = cstmt.getInt (1); --the first argument returns the new salary
System.out.println ("The new salary for SCOTT is: " + new_salary);
}
}