作为一项作业,我需要创建一个 PL/SQL 存储过程将教师成员添加到数据库中。
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;
完成这个步骤后,我需要进行一个Java调用来执行这个过程,我尝试使用以下代码:
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);
我将上述代码放入了一个try catch块中,但一直在抛出错误。我根据其他网站上的内容尝试了几种"in"字符串的变体: in = "{call ADDFACULTYDEPSAL ... in = "call ADDFACULTYDEPSAL ...
在这里查看:MySQL Connector指南, 我还尝试将stmt更改为可调用语句,如下所示:
CallableStatement stmt;
if(a == 1){
stmt = dbConnection.prepareCall("{call ADDFACULTYDEPTSAL(?,?,?)}");
} else {
stmt = dbConnection.prepareCall("{call ADDFACULTYUNISAL(?,?,?)}");
}
然而,尝试这种方式似乎行不通,因为我需要将超过两个变量传递到该过程中。
有人能告诉我我哪里错了吗?