我正在尝试使用以下预准备语句更新MySQL点类型:
String selectQry = ("UPDATE at_group " +
"SET grp_country=?, grp_state=?, grp_region=?, grp_district=?, " +
"grp_name=?, grp_section=?, grp_sub_section=?, grp_archived=?, " +
"grp_hall_geoPoint=?, grp_nas=? " +
"WHERE grp_id=?;");
// Create a statement and execute the query on it
String geo = ("POINT" + "(" + latitude + " " + longditude + ")");
ps.setString(1, country);
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, geo);
ps.setString(10, nas);
ps.setString(11, groupID);
ps.executeUpdate();
我收到以下错误:
SQLException in updateGroup: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Cannot get geometry object from data you send to the GEOMETRY field
我的输入是-33.8和151.1
我按照链接(其中一些已损坏)找到了答案。我已经在这里发布了答案,为大家带来了好处。答案是:
String selectQry = ("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=? " +
"WHERE grp_id=?;");
// Create a statement and execute the query on it
ps.setString(1, country);
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, groupID);
ps.executeUpdate();