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 
长春语林科技 阅读(665) 
评论(0)  编辑  收藏  所属分类: 
util