gpt4 book ai didi

java - Insert INTO 查询不适用于一种方法但适用于另一种方法

转载 作者:搜寻专家 更新时间:2023-10-30 22:01:00 24 4
gpt4 key购买 nike

我有两种方法,一种有效,另一种不适用于插入查询

// this one fails
public void product(String product, String quantity, String price,
String date) throws SQLException {
try {
statement.execute("INSERT INTO product (productn,quantity,price,date) VALUES ('" + product + "','" + quantity + "','" + price + "','" + date + "')");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

// this one works
public void customer(String name, String q, String p, String pro)
throws SQLException {
try {
statement.execute("INSERT INTO Customer (name,price,product,quantity) VALUES ('" + name + "','" + q + "','" + p + "','" + pro + "')");
} catch (Exception e) {
System.out.println("problem in Customer insert !");
}
}

一种工作正常的方法意味着它将数据插入表中,但另一种方法给出以下错误:

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement

最佳答案

试试这个:

INSERT INTO product ([productn],[quantity],[price],[date]) VALUES ('" + product + "','" + quantity + "','" + price + "','" + date + "')

让我知道它是否有效

关于java - Insert INTO 查询不适用于一种方法但适用于另一种方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14139638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com