我有:

String query = "INSERT INTO Basestations VALUES(?, ?, ?, ?, ?, ?, ?,"
               + "?, ?, ?, ?, ?, ?, ?, ?)";


PreparedStatement prep = conn.prepareStatement(query);

prep.setInt(1, profile.getNetworkId());
prep.setInt(2, profile.getBaseStationId());
prep.setInt(8, profile.getLoadLevel());
prep.setInt(11, profile.getPositionX());
prep.setInt(12, profile.getPositionY());
prep.setInt(13, profile.getPort());

prep.setDouble(3, profile.getSignalStrength());
prep.setDouble(4, profile.getFrequency());
prep.setDouble(6, profile.getMaxBitrate());
prep.setDouble(7, profile.getGuaranteedBitrate());
prep.setDouble(10, profile.getRange());

prep.setString(5, profile.getNetworkType());
prep.setString(9, profile.getProvider());
prep.setString(14, profile.getCharging());

prep.setBoolean(15, true);


prep.executeUpdate(query);

我得到:
信息:SQL异常:
信息:州:42000
信息:消息:您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以获取在''附近使用的正确语法?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' 在第1行
信息:错误:1064
怎么了?

最佳答案

当不需要时,您将向executeUpdate()方法传递一个表示无效SQL语句的字符串。试着做prep.executeUpdate();

10-06 09:52