日期:2014-05-20 浏览次数:20926 次
PreparedStatement psmcnn.prepareStatement("insert into bbs values(seq.nextval,?,?)",Statement.RETURN_GENERATED_KEYS );
......
psm.executeUpdate();
ResultSet rs = psm.getGeneratedKeys();//获取自动递增字段的结果集
rs.next();
int id = rs.getInt(1) //获取seq.nextval的值
public Integer getId() throws Exception{
Connection conn=null;
PreparedStatement pstm=null;
ResultSet rs=null;
try{
conn=JdbcUtil.getConnection();
String sql="select seq.nextval from dual";
pstm=conn.prepareStatement(sql);
rs=pstm.executeQuery();
Integer id=null;
if(rs.next()){
id=rs.getInt(1);
}
return id;
}finally{
if(rs!=null) try{ rs.close(); } catch(Exception e){}
if(pstm!=null) try{ stm.close(); } catch(Exception e){}
if(conn!=null) try{ conn.close(); } catch(Exception e){}
}
}
------解决方案--------------------
不好意思没仔细看你下面已经写了代码了.
那lz可以参考下我的代码就是我以前在oracle数据库用jdbc写的