1

I'm getting a MySQLSyntaxErrorException: Unknown column 'quantity' in 'field list' error when inserting value to my mysqldatabase. I have the column quantity in my table but it says unknown column in field list. Below is my code and I have no idea what's wrong with it. Can anyone help me? Thank you in advance.

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);

Adding the TABLE details to the question (taking it from the comment) for readability:

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
8
  • Please provide output of: describe tbl_reservations. Commented Oct 16, 2016 at 14:46
  • 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 Commented Oct 16, 2016 at 14:55
  • Do you use hibernate or maybe some other orm? Commented Oct 16, 2016 at 15:10
  • i dont know what orm or hibernate means. sorry can u explain? Commented Oct 16, 2016 at 15:13
  • the query runs and it inserts data to my table but its throwing that exception. i dont know why Commented Oct 16, 2016 at 15:15

1 Answer 1

0

Hibernate Field Naming with Spring Boot

follow this guide : https://www.baeldung.com/hibernate-field-naming-spring-boot

with spring-boot-starter-data-jpa

If we create an entity call Account

@Entity
public class Account {
  @Id
  private Long id;
  private String defaultEmail;
}

Hibernate: create table account (id bigint not null, default_email varchar(255))

we don't need to specify the physical-strategy or the implicit-strategy properties in this case since we are accepting the defaults.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.