实现spring中往oracle数据库插数据后返回主键

KeyHolder keyHolder = new GeneratedKeyHolder();
int rowsAffected = jdbcTemplate.update( new PreparedStatementCreator() { 
     public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { 
        PreparedStatement ps = conn.prepareStatement(insert_userpayment, new String[] {"id"});
        //ps.setString 
          return ps; 
                } 
     },keyHolder); 
    payment.setId(keyHolder.getKey().longValue()); // 保存插入的这条记录的主键id
 
 
而mysql中则不需要添加new String[] {"id"}

你可能感兴趣的:(spring,oracle,职场,休闲)