在向我的 mysql 数据库插入值时,出现 MySQLSyntaxErrorException: Unknown column 'quantity' in 'field list'
错误。我的表中有列数量,但它在字段列表中显示未知列。下面是我的代码,我不知道它有什么问题。谁能帮我?提前谢谢你。
query = "insert into tbl_reservations(cust_name,product_name,quantity,price,total,purchase_date,order_number,status) values ('" + nam + "','" + name[x] + "','" + quantity[x] + "','"+ fprice[x] + "','" + price[x] + "','" +currentDate+ "','" + rnum + "','" + status + "')";
System.out.println(query);
int i = st.executeUpdate(query);
System.out.println(query);
将 TABLE 详细信息添加到问题(从评论中获取)以提高可读性:
Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
cust_name varchar(255) YES NULL
quantity int(11) YES NULL
price double NO NULL
total double NO NULL
purchase_date date YES NULL
order_number int(255) NO NULL
status varchar(255) NO NULL
最佳答案
使用 Spring Boot 的 Hibernate 字段命名
遵循本指南:https://www.baeldung.com/hibernate-field-naming-spring-boot
使用 spring-boot-starter-data-jpa
如果我们创建一个实体调用 Account
@Entity
public class Account {
@Id
private Long id;
private String defaultEmail;
}
Hibernate:创建表帐户(id bigint 不为空,default_email varchar(255))
在这种情况下,我们不需要指定物理策略或隐式策略属性,因为我们接受默认值。
关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Unknown column 'quantity' in 'field list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40071255/