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 的值只有在同一次會話中,發(fā)生seq_atable.nextval后有效:) 所以不會存在取錯值的問題。
oracle創(chuàng)建觸發(fā)器,不用管ID
使用序列+觸發(fā)器實現(xiàn)自增,插入語句不需要管自增字段
如:create or replace trigger trg_atable before insert on atable for each row begin select seq_atable.nextval into :new.id from dual; end;
插入數(shù)據(jù):
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
長春語林科技 閱讀(633)
評論(0) 編輯 收藏 所屬分類:
util