Writing Java Stored Procedures :
To create a java procedure with oracle lite you need to follow the folllowing step :
create a Java class "Emp_class" in a file called EM.java to implement the get_salary method:
Code:
import java.sql.*;
public class Emp_class {
public static int get_salary(Connection conn, int empno) throws Exception
{
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("SELECT sal, nvl(comm,0) FROM EMP WHERE empno="+empno);
int sal = 0;
if (r.next()) {
sal = r.getInt(1) + r.getInt(2); /* sal = :sal + :comm */
} else {
throw new Exception("Employee "+empno+" is invalid.");
}
r.close(); s.close();
System.out.println("Salary for employee "+empno+" is "+sal);
return sal;
}
}
And attach this java class to the table named Employees :
ALTER TABLE EMPLOYEES ATTACH SOURCE "Emp_class" IN '.';
To execute the Method within ODBC :
SQLExecDirect(hstm, "SELECT EMP."get_salary"(7369) FROM DUAL");
Bookmarks