int i=statement.executeUpdate("INSERT INTO CHARGE_T (CHA_FIRSTWEIGHT, CHA_FIRSTWPRICE, CHA_SECONDWPRICE, CHA_FIRSTVOLUME, CHA_FIRSTVPRICE, CHA_SECONDVPRICE, cha_status,cha_ran_name) VALUES ('"+chargeVO.getCha_firstweight()+"', '"+chargeVO.getCha_firstwprice()+"', '"+chargeVO.getCha_secondwprice()+"', '"+chargeVO.getCha_firstvolume()+"', '"+chargeVO.getCha_firstvprice()+"', '"+chargeVO.getCha_secondvprice()+"','未通过','"+chargeVO.getCha_ran_name()+"')");
int j=statement.executeUpdate("update range_t set ran_cha_id=(?) where cha_ran_name=ran_name");(?)那里怎么才能获得上面刚插入数据库的那条数据的id,求教
2,如果不通过id ,其他字段不能唯一标识,那你只能自己插入的时候给一个id ,这样你就可以知道你插入记录的id了
3,直接查询你插入CHARGE_T表的当前sequence(不是很安全),
int i=statement.executeupdate("
INSERT INTO CHARGE_T (CHA_FIRSTWEIGHT, CHA_FIRSTWPRICE, CHA_SECONDWPRICE,
CHA_FIRSTVOLUME, CHA_FIRSTVPRICE, CHA_SECONDVPRICE, cha_status,cha_ran_name)
VALUES ('"+
chargevo.getcha_firstweight()+"', '"+
chargevo.getcha_firstwprice()+"', '"+
chargevo.getcha_secondwprice()+"', '"+
chargevo.getcha_firstvolume()+"', '"+
chargevo.getcha_firstvprice()+"', '"+
chargevo.getcha_secondvprice()+"','未通过','"+
chargevo.getcha_ran_name()+"')");
//这里的sq就是你刚才插入的序列的值
int sq = statement.execute("select (s_louzhu.nextval-1) from dual");int j=statement.executeUpdate("update range_t set ran_cha_id="+sq +" where cha_ran_name=ran_name");
希望楼主下回发帖的时候 在代码里适当的加入换行
String sql1="update range_t set ran_cha_id=seq_charge_t.currval where '"+chargeVO.getCha_ran_name()+"'=range_t.ran_name";
上面就解决了,谢谢了