使用JDBC预准备语句的SQL 1064语法错误 [英] SQL 1064 Syntax Error using a JDBC prepared statement

查看:108
本文介绍了使用JDBC预准备语句的SQL 1064语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

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 INFO:消息:您的SQL语法有错误;可能是错误.在以下位置检查与MySQL服务器版本相对应的手册以获取正确的语法,以在'?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)中使用正确的语法.第1行 信息:错误:1064

INFO: SQL Exception: INFO: State : 42000 INFO: Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' at line 1 INFO: Error : 1064

怎么了?

推荐答案

您不需要时将表示无效SQL语句的字符串传递给executeUpdate()方法.尝试只做prep.executeUpdate();.

You're passing an string representing an invalid SQL statement to the executeUpdate() method when you don't need to. Try just doing prep.executeUpdate();.

这篇关于使用JDBC预准备语句的SQL 1064语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆