我试图在我的MySQL数据库中插入一条记录,该记录应插入表 medication_profile 中,但我收到的错误是:

线程“main”中的异常com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以便在第1行使用'pharmac_type,diabetic_id,times_a_day,dose)附近的正确语法'VALUES('injections',2,1,'18')'

我在java中用来插入此记录的代码如下:

PreparedStatement addMedicationStm = con.prepareStatement("INSERT INTO medication_profile"

+ ", medication_type, diabetic_id, times_a_day, dose) "

+ "VALUES (?,?,?,?))", Statement.RETURN_GENERATED_KEYS);

addMedicationStm.setString(1, medication.getMedicationType());

addMedicationStm.setInt(2, medication.getDiabeticID());

addMedicationStm.setInt(3, medication.getTimesPerDay());

addMedicationStm.setString(4, medication.getDose());

addMedicationStm.executeUpdate();

ResultSet rs = addMedicationStm.getGeneratedKeys();

if (rs != null && rs.next()) {

medication.setDiabeticID(rs.getInt(1));

addMedicationStm.close();

con.close();

}

我找不到错误的位置,因为我看到插入语法是正确的

有什么建议?

提前致谢

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐