Beispiel #1
0
 /**
  * insert into 并返回最后的响应的id
  *
  * @param sql
  * @param params
  * @return
  * @throws SQLException
  */
 public int excuteInsetIdi(String sql, Object... params) throws SQLException {
   printIn(sql);
   printIn("params length:" + params.length);
   for (int i = 0; i < params.length; i++) {
     printIn("params" + i + ":" + params[i]);
   }
   Connection conn = getConnection();
   QueryRunner qr = new QueryRunner();
   PreparedStatement pst = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
   qr.fillStatement(pst, params);
   pst.execute();
   ResultSet rs = pst.getGeneratedKeys();
   return rs.next() ? rs.getInt(1) : 0;
 }
Beispiel #2
0
 public void close(ResultSet rs) throws SQLException {
   if (rs != null) {
     rs.close();
   }
 }