日期:2014-05-16 浏览次数:20496 次
final String sqlstr = "insert into tb_user(userId,userName,sex) values(seq_user_id.nextval,?,?)" KeyHolder keyHolder = new GeneratedKeyHolder(); int result = 0; try { result = this.getJdbcTemplate().update( new PreparedStatementCreator() { public PreparedStatement createPreparedStatement( Connection conn) throws SQLException { PreparedStatement ps = null; ps = conn.prepareStatement(sqlstr, new String[] { "userId" }); ps.setString(1, userName); ps.setString(2, sex); return ps; } }, keyHolder); } catch (Exception e) { result = 0; } if (result > 0) userId= keyHolder.getKeyList().get(0).toString();