DBMS Week-9 Assignment
DBMS Week-9 Assignment
two parameters:
2. increment (FLOAT): The increment amount to be added to the employee's current salary.
BEGIN
UPDATE employees
WHERE id = employee_id;
END;
In SQLJ, you would use a CALL statement embedded within SQLJ syntax to execute this procedure.
Here’s how the Java code would look:
import java.sql.*;
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
} catch (SQLException e) {
e.printStackTrace();
throw e;
}
try {
manager.updateEmployeeSalary(101, 500);
} catch (SQLException e) {
1. Establish Connection: The Connection object (conn) connects to the database. You would
replace the database URL, username, and password with the actual connection details.
2. SQLJ Block: Inside the SQLJ block (#sql [conn] { ... }), the CALL statement is used to invoke the
update_employee_salary stored procedure. Here, the :employeeId and :increment are the
parameters passed to the stored procedure, and they are linked to the variables in Java.
3. Calling the Method: The updateEmployeeSalary method is called in the main method to
update the salary for a specific employee.
Notes
SQLJ Translator: SQLJ code requires translation before compilation, so a precompiler (SQLJ
translator) processes SQLJ statements into standard Java code and JDBC calls.
Error Handling: SQL exceptions are caught and printed for debugging purposes.