我正在使用一个prepared语句尝试向mysql表中插入新行,如果索引存在,则执行更新。我相当肯定,这个问题是有关的“点”字段标记为“grp\U霍尔\U地球点”。我收到错误:
"SQLException in updateGroup: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'SET grp_country='Australia', grp_state='New South Wales', grp_region='Sydney Nor' at line 1"
传递的值是:
public static void updateGroup(String state,
String region, String district, String group, String section,
String subSection, String archiveDate, String latitude, String longditude, String nas) {[/code]
准备好的声明是:
String insertUpdateQry = ("INSERT INTO at_group " +
"(grp_country, grp_state, grp_region, grp_district, grp_name, " +
" grp_section, grp_sub_section, grp_archived, grp_hall_geoPoint, grp_nas) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, PointFromText(CONCAT('POINT(', ?, ' ', ?, ')')), ?)" +
"ON DUPLICATE KEY " +
"UPDATE at_group " +
"SET grp_country=?, grp_state=?, grp_region=?, grp_district=?, " +
"grp_name=?, grp_section=?, grp_sub_section=?, grp_archived=?, " +
"grp_hall_geoPoint=PointFromText(CONCAT('POINT(', ?, ' ', ?, ')')), grp_nas=?;");
try {
// Get Connection and Statement from DataSource
c = ds.getConnection();
ps = c.prepareStatement(insertUpdateQry);
try {
// Create a statement and execute the query on it
ps.setString(1, "Australia");
ps.setString(2, state);
ps.setString(3, region);
ps.setString(4, district);
ps.setString(5, group);
ps.setString(6, section);
ps.setString(7, subSection);
ps.setString(8, archiveDate);
ps.setString(9, latitude);
ps.setString(10, longditude);
ps.setString(11, nas);
ps.setString(12, "Australia");
ps.setString(13, state);
ps.setString(14, region);
ps.setString(15, district);
ps.setString(16, group);
ps.setString(17, section);
ps.setString(18, subSection);
ps.setString(19, archiveDate);
ps.setString(20, latitude);
ps.setString(21, longditude);
ps.setString(22, nas);
ps.executeUpdate();
以下是唯一索引:grp\u country、grp\u state、grp\u region、grp\u district、grp\u name、grp\u section、grp\u sub\u section
grp\ U hall\ U地质点是类型点
我使用测试数据触发更新和插入,结果相同。
2条答案
按热度按时间6bc51xsx1#
您可以将此查询更改为(已删除表名和set语句):
此处引用:http://www.mysqltutorial.org/mysql-insert-or-update-on-duplicate-key-update/
7gcisfzg2#
语法错误与点数据类型无关。不能提供表名和
set
之后update
在on duplicate key update
条款。所以
你只需写下: