problem on java stored procedures [message #366768] |
Mon, 11 December 2000 00:39 |
sreelatha
Messages: 3 Registered: December 2000
|
Junior Member |
|
|
I have a problem. It will be of great help to me if you can suggest any solution for my problem.
I have written a java program which has a insert statement into a table in the database, compiled it and executed it. I got the intended result ie I am able to insert a row into the table.
The same java code( I have removed the main part), I have compiled it and loaded the class into the database with javaload command. In the datbase I am able to see that the javaclass is in valid state. I have written a stored procedure which is wrapper for the above java class( which is having a method).
When I execute the stored procedure , It says that the stored procedure is successfully executed but it is not inserting a row into the database table.
I am sending code for clarity purpose
java code
-------------
import java.sql.*;
import java.io.*;
public class DBTrigger {
public static void logSal (int empID, float oldSal, float newSal)
throws Exception {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:sree","sree","sree");
String sql = "INSERT INTO sal_audit VALUES (?, ?, ?)";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, empID);
pstmt.setFloat(2, oldSal);
pstmt.setFloat(3, newSal);
pstmt.executeUpdate();
System.out.println("Sree"+empID+"Latha"+oldSal+newSal);
pstmt.close();
}
catch(Exception m)
{ m.printStackTrace();}
}
/* public static void main(String args[[]])
{
try{
DBTrigger dbt = new DBTrigger();
dbt.logSal(7902,1200,5000);
}catch(Exception e)
{ e.printStackTrace();}
} */
}
stored procedure
------------------------
CREATE OR REPLACE PROCEDURE log_sal (
emp_id NUMBER, old_sal NUMBER, new_sal NUMBER)
AS LANGUAGE JAVA NAME
'Sree.logSal(int, float, float)';
/
Thanks & Regards
Sreelatha
|
|
|
|
Re: problem on java stored procedures [message #366781 is a reply to message #366768] |
Wed, 27 December 2000 22:27 |
Murthy
Messages: 9 Registered: March 2000
|
Junior Member |
|
|
Hi Sree,
You need to put a "commit; " statement after inserting. that is theproblem.
One more thing is, could yopu please tell me how to load a class file into databas and call it in your javacode?
Please tell me the procedure. I am doing a Live GE project I need that procedure. First of all what is thestructure of the database table to inssert a java class and procedure to call it form other hjava program. is this possible using jdk1.1.6 because we have to use jdk1.1.6 with jdbc1.0 . Please send me the procedure.
Thanks & Regards,
Murthy
|
|
|