注册 登录
编程论坛 J2EE论坛

[求助]存储过程的调用.

shithanwa 发布于 2007-04-19 20:25, 829 次点击

关于存储过程的疑问????


比如说:有一个学生成绩表(t_score),它有如下字段:学号(stu_id),课程号(cour_id),课程名(cour_name),成绩(score);
现在要通过一个已知的学生学号,删除对应的学生成绩信息.问题是如何写一个存储过程( 学号是由前台输入的),以便JAVA程序调用此过程,删除对应记录?我写的过程出现如下错误:(Warning: Procedure created with compilation errors),不知道where后面怎么写?
请多指教!

8 回复
#2
天使坠落的眼泪2007-04-19 22:09
有片段代码么?如果有贴上来,这样说很模糊
#3
shithanwa2007-04-20 10:53

sql脚本:
create table T_TB0606609_score(
stu_id varchar2(20),
cour_id varchar2(20),
cour_name varchar2(20),
score varchar2(20),
constraint p_score primary key(cour_id)
);

create or replace procedure p_del_score(
stu_id varchar2,
cour_id varchar2,
cour_name varchar2,
score varchar2,
)
is
begin
delete from T_TB0606609_score where p_stu_id=stu_id;
commit;
end p_del_score;

JAVA调用:
public void delScore(String studentId) {
conn = DBHelper.getConnection();
sql = "{call p_del_score(?)}";
try {
cstmt = conn.prepareCall(sql);
cstmt.setString(1, studentID);
cstmt.executeUpdate();

System.out.println("增加数据成功");
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
谢谢指教!

#4
shithanwa2007-04-24 20:28
大哥帮我看看啊!
#5
支离破碎2007-04-25 09:25
报的错误是你存储过程写的有问题。。。

你先试一下这个能不能在数据库中运行先
#6
shithanwa2007-05-09 00:29

哦,存储过程中变量没区分开.应该是这样的吧:
sql脚本:
create table T_TB0606609_score(
stu_id varchar2(20),
cour_id varchar2(20),
cour_name varchar2(20),
score varchar2(20),
constraint p_score primary key(cour_id)
);

create or replace procedure p_del_score(
p_stu_id varchar2,
p_cour_id varchar2,
p_cour_name varchar2,
p_score varchar2
)
is
begin
delete from T_TB0606609_score where stu_id=p_stu_id;
commit;
end p_del_score;

#7
支离破碎2007-05-09 09:06
这个。。。只有你自己调试好存储过程了,N久没搞过这了,都忘光了。。
#8
yidong2007-05-09 09:44

你过程就只需要一个参数,你传那么多进去干嘛?
你调用的时候是"{call p_del_score(?)}";也是一个传参数;
参数个数也不会匹配吧?
而且过程里面就一句SQL;需要用过程吗?

#9
shithanwa2007-05-10 13:59
是的传多了没用的参数,但参数还是会匹配的.
"{call p_del_score(?)}"的参数是SQL句中的.

说的就是要调用存储过程,当然不用存储过程都会了;最要人头痛的查询的存储过程.
1