java 调用sequence,sequence在oracle,db2中的操作差别及java中调用方法

一 sequence的定义

oracle中定义:

create sequence test minvalue 1 maxvalue 1000 start with 1 increment by 1 cache 20 nocycle order;

DB2中定义:

create sequence test as bigint start with 1 increment by 1 minvalue 1 nomaxvalue nocycle cache 20 order;

二 sequence 的读取

oracle中读取

select test.nextValue from dual;

db2 中读取

select next value for seq_logid from Sysibm.sysdummy1

三 sequence的作为字段插入

oracle中插入

insert into test_table(id ,name) values(test.nextvalue,"testName");

db2中插入

insert into test _table(id,name) values(next value for test,"testName")

四 java调用sequence方法

Connection conn;

PreparedStatement ps=null;

try{

conn=this.getConnection();//此方法自己实现

String insSql="insert into test_table(uid,name) VALUES(NEXT VALUE FOR test,?)";

ps=conn.prepareStatement(insSql);

ps.setString(1, “test name”);

ps.execute();

ps.close();

ps=null

}catch(Exception e) {

//......

}finally{

//....

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值