0

我试图添加一条记录做 MariaDB 数据库使用 Sql2o 和 IntelliJ

所有字段都有 typeString并且在 Database 中有 type varchar

但我得到了下面的错误(java.sql.SQLSyntaxErrorException)

Error in executeUpdate, You have an error in your SQL syntax; check the manual that corresponds to 
your MariaDB server version for the right syntax to use near 'desc, manufacturer, category, 
condition) values ('4082304923748','iPhone X','...' at line 1
public static void add(Product product, HttpServletRequest request) {
        final String sql = "insert into product (item_code, name, unit_price, units_in_stock, desc, manufacturer, category, condition) " +
                "values (:item_code,:name,:unit_price,:units_in_stock,:desc,:manufacturer,:category,:condition)\n";
        try (Connection con = sql2o.open()) {
            //con.createQuery(sql).bind(product).executeUpdate();
            con.createQuery(sql).addParameter("item_code", product.getItem_code())
                    .addParameter("name", product.getName())
                    .addParameter("unit_price", product.getUnit_price())
                    .addParameter("units_in_stock", product.getUnits_in_stock())
                    .addParameter("desc", product.getDesc())
                    .addParameter("manufacturer", product.getManufacturer())
                    .addParameter("category", product.getCategory())
                    .addParameter("condition", product.getCondition())
                    .executeUpdate();
        }
}
4

1 回答 1

0

DESCandCONDITION是保留关键字,不能用作列名

更多

于 2021-08-18T17:29:31.257 回答