gpt4 book ai didi

java - SQL语句插入时出错

转载 作者:行者123 更新时间:2023-11-30 07:25:43 24 4
gpt4 key购买 nike

我尝试将用户输入的数据插入数据库,但收到错误“语法错误:在第 1 行第 160 列遇到“[”。”这是我的代码,我做错了什么?`

if (action.getSource() == Submit_button)
{
try
{
sql = "INSERT INTO Customer (FNAME, LNAME, AGE, LICNUM, STATE, CAR_TYPE, RENTDATE, RETURNDATE, TOTAL, PAYTYPE, RETURNED) VALUES(";
sql = sql + "'" + f_name.getText() + "'" + "," + "'" + l_name.getText() + "'" + "," + Age + "," + "'" + liscense_num.getText() + "'" + "," + "'"
+ issuing.getText() + "'" + "," + "'" + car_select.getToolkit() + "'" + "," + "'" + rental.getText() + "'" + "," + "'" + return_d.getText() + "'"
+ "," + total.getText() + "," + "'" + button_val.getText() + "'" + "," + "'true'" + ")";
myStatement.execute(sql);
System.out.print("Record has Been added to database");
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

最佳答案

你能把查询改成这样吗?

sql = "INSERT INTO Customer (FNAME, LNAME, AGE, LICNUM, STATE, CAR_TYPE, RENTDATE, RETURNDATE, TOTAL, PAYTYPE, RETURNED) VALUES('"+f_name.getText()+"','"+l_name.getText()+"','"+Age+"','"+liscense_num.getText()+"','"+issuing.getText()+"','"+car_select.getToolkit()+"','"+rental.getText()+"','"+return_d.getText()+"','"+total.getText()+"','"+button_val.getText()+"','true') ";

关于java - SQL语句插入时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36831166/

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