For homework I have to create a pl/sql stored procedure to add a facutly member to a database
CREATE OR REPLACE PROCEDURE ADDFACULTYDEPTSAL
(facid IN NUMBER,
facname IN VARCHAR,
depID IN NUMBER)
AS
sal NUMBER;
BEGIN
CALCSALDEPT(depID, sal);
IF sal >= 50000
THEN
sal := sal*.9;
ELSE
IF sal >= 30000
THEN
sal := sal*.8;
END IF;
END IF;
INSERT INTO FACULTY(fid, fname, deptid, salary)
VALUES(facid, facname, depID, sal);
END ADDFACULTYDEPTSAL;
Having done that, I need to make a java call for said procedure, which I've tired to do with:
Statement stmt = dbConnection.createStatement();
String in;
if(a == 1){
in = "ADDFACULTYDEPTSAL("
+ fid.getText() + "','"
+ fname.getText() + "','"
+ did.getText() + "')";
} else {
in = "ADDFACULTYUNISAL("
+ fid.getText() + "','"
+ fname.getText() + "','"
+ did.getText() + "')";
}
stmt.executeQuery(in);
I have the above in a try catch block that keeps throwing an error. I have tried several variants on the string "in" based on what I saw on other websites:
in = "{call ADDFACULTYDEPSAL ...
in = "call ADDFACULTYDEPSAL ...
looking here: MySQL Connector Guide
I also tried changing stmt to a callable statement as such:
CallableStatement stmt;
if(a == 1){
stmt = dbConnection.prepareCall("{call ADDFACULTYDEPTSAL(?,?,?)}");
} else {
stmt = dbConnection.prepareCall("{call ADDFACULTYUNISAL(?,?,?)}");
}
However, trying this way doesn't seem to work because I need to pass more than two variables into the procedure.
Can anyone tell me what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…