在jsp中怎样使用oracle中定义的序列

deane 2002-09-26 04:36:49
我在oracle 定义了个序列seq1,用来实现对字段(pk)自动加一的功能,
若 insert into table1(a,b) values(seq1.nextnal(),value2)好使,
但我想做的是使用preparestatement,
代码如下
PreparedStatement prestmt=conn.prepareStatement("insert into bbs(a,b) values(?,?)");
prestmt.setBytes(2,cardid.getBytes());
prestmt.setBytes(1,seq2.nextval());

这时报错,general error
那位大侠能告诉我怎么做,

...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiuyang_wang 2002-09-27
  • 打赏
  • 举报
回复
用触发器自动后台完成吧,这样又省力又省时,另外触发器中可以直接对:new符值,所以出现自动加一的列就可以用序列和触发器实现了.
jlandzpa 2002-09-26
  • 打赏
  • 举报
回复
create or replace trigger tri_ryjbxx
after update of scbz,csbz or delete on ryjbxx
for each row
begin
if deleting then
delete from ryxxzb
where rybh=:old.rybh;
delete from ryxxzb1
where rybh=:old.rybh;
delete from ryxxzb2
where rybh=:old.rybh;
end if;
if updating then
update ryxxzb
set scbz=:new.scbz,csbz=:new.csbz
where rybh=:new.rybh;
update ryxxzb1
set scbz=:new.scbz,csbz=:new.csbz
where rybh=:new.rybh;
update ryxxzb2
set scbz=:new.scbz,csbz=:new.csbz
where rybh=:new.rybh;
end if;
end;
/
deane 2002-09-26
  • 打赏
  • 举报
回复
怎么写触发器呢
zhaoyongzhu 2002-09-26
  • 打赏
  • 举报
回复
改成这样不行吗:
PreparedStatement prestmt=conn.prepareStatement("insert into bbs(a,b) values(seq2.nextval(),?)");
prestmt.setBytes(2,cardid.getBytes());


你可以在表上建一个触发器,这样就不用给这个字段(a)赋值了
deane 2002-09-26
  • 打赏
  • 举报
回复
写错了,seq2.nextval

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧