posts - 325,  comments - 25,  trackbacks - 0
mysql:   select LAST_INSERT_ID() as lastid
mssqlsever:  
public int updatePara(String sql) {
  int id = 0;
  try {
   st = con.createStatement();
   if (st.executeUpdate(sql) == 1) {
    rs = st.executeQuery("SELECT @@IDENTITY AS IDX_NO");
    if (rs.next()) {
     id = rs.getInt(1);
    }
    con.commit();
   } else {
    con.rollback();
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return id;
 }

oracle:
$query="select seq_atable.currval from dual";
seq_atable.currval 的值只有在同一次会话中,发生seq_atable.nextval后有效:) 所以不会存在取错值的问题。

oracle创建触发器,不用管ID
使用序列+触发器实现自增,插入语句不需要管自增字段
如:create or replace trigger trg_atable before insert on atable for each row begin select seq_atable.nextval into :new.id from dual; end;

插入数据:
create or replace trigger TRG_SEO_ONLINE_PHOTO
  before insert on SEO_ONLINE_PHOTO
  for each row
begin
  select SEQ_ONLINE_PHOTO.nextval into :new.ONPHOTO_ID from dual;
end;

posted on 2008-12-16 13:34 长春语林科技 阅读(623) 评论(0)  编辑  收藏 所属分类: util

只有注册用户登录后才能发表评论。


网站导航:
 
<2008年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

 

长春语林科技欢迎您!

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜