数据转换错误H2数据库

时间:2016-02-25 07:11:31

标签: java jdbc sql-update h2

我正在从Java Application运行数据库查询。

String id = app.getVariable("Product Id"),
                name = app.getVariable("Product Name"),
                rate = app.getVariable("Rate"),
                type = app.getVariable("Type"),
                desc = app.getVariable("Description"),
                qty = app.getVariable("Quantity"); // Returns String from TextFields

        type = type.equalsIgnoreCase("LIMITED") ? "TRUE" : "FALSE";


        try {
            String query = "UPDATE COUNTER.PRODUCTS SET TITLE = ? AND RATE = ? AND IS_LIMITED = ? AND DESCRIPTION = ? WHERE ID = ?";
            PreparedStatement stmt = MainApp.getConnection().prepareStatement(query);

            stmt.setString(1, name);
            stmt.setDouble(2, Double.parseDouble(rate));
            stmt.setBoolean(3, Boolean.parseBoolean(type));
            stmt.setString(4, desc);
            stmt.setInt(5, Integer.parseInt(id));

            stmt.executeUpdate();
        } catch(Exception ex1){
            System.out.println( ex1.toString() );
        }

但遇到SQLException

  

org.h2.jdbc.JdbcSQLException:数据转换错误转换"扫描&#34 ;; SQL语句:
  UPDATE COUNTER.PRODUCTS SET TITLE =?和率=? AND IS_LIMITED =? AND DESCRIPTION =?在哪里ID =? [22018-187]

插入数据查询工作正常,但我无法执行更新查询。

1 个答案:

答案 0 :(得分:3)

像这样写下你的查询:

  UPDATE COUNTER.PRODUCTS SET TITLE = ? ,RATE = ? ,IS_LIMITED = ? ,DESCRIPTION = ? WHERE ID = ?

使用逗号,代替and