无法使用循环将数据插入数据库准备状态

时间:2016-09-08 01:45:23

标签: java mysql

Hy,我想使用prepareStatement方法将数据插入数据库,并且它正常工作,但是当我从循环插入数据时,数据不会插入到db。 这是我的代码:

PreparedStatement stmts = connection.prepareStatement(
    "INSERT INTO detil_bet (id_user, id_room, id_game, bettype, total, win, lose) VALUES (?, ?, ?, ?, ?, ?, ? )"
);
stmts.setInt(1, Uid);
stmts.setInt(2, idRoom);
stmts.setInt(3, idg);
int count = 0;
int size = 10;
String betsmall=""+0;
String betbig = ""+1;
String Z = "";
for (int i = 0; i < size; i++) {
    String[] b = {betsmall,betbig};
    count++;
    if(!b[i].equals(""+0)) {
        if(count > 0) {
             Z += "; ";
        }
        Z += "S" + count + ":" + b[i];
        stmts.setString(4, Z);
    }
}
stmts.setInt(5, tobet);
      if(pay >= tobet){
      stmts.setInt(6, pay - tobet);
      }else if (pay <= tobet){
          stmts.setInt(6, 0);
      }
      if(tobet >= pay){
          stmts.setInt(7, tot + (tot*-2));
      }
      else if (tobet <= pay){
          stmts.setInt(7, 0);
      }
      stmts.executeUpdate();

    }

索引1,2和3工作正常,问题是索引号4,它不起作用

0 个答案:

没有答案