0

I am trying to insert data from my netbeans to mysql workbench. there is no problem with the query but when I run the program a message box appear "Unknown column 'empJob' in 'field list '" . What seems to be the problem? and just to Know i tried this on another table and it works just fine! but in this one it doesn't work!

int id, Salary;
String name, Address, Jop;

id = Integer.parseInt(tNo.getText());
name = tName.getText();
Address = tAddress.getText();
Jop = tJop.getText();
Salary = Integer.parseInt(tNo.getText());

String sql = "insert into employee(empid,empName, empAddress,empJob,empSalary) values('" + id + "','" + name + "' , '" + Address + "','" + Jop + "','" + Salary + "')";

Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
int x = st.executeUpdate(sql);
if (x > 0) {
    JOptionPane.showMessageDialog(prev, x + "rows effected");
} else {
    JOptionPane.showMessageDialog(prev, "insert failed");
}

wake-0
  • 3,918
  • 5
  • 28
  • 45
  • I think the problem is with the quotes. Check this answer: https://stackoverflow.com/a/1346298/20666497 – Albina Dec 20 '22 at 19:03
  • 1) *i tried this on another table and it works just fine!* - well that doesn't mean both tables have the same column name. We can't debug this for you. 2) you should be using a `PreparedStatement` to make the SQL easier and less error prone. Check out: https://stackoverflow.com/a/24102087/131872 for a simple example of how to create the statement and use parameters. – camickr Dec 20 '22 at 19:04

1 Answers1

0

Do you have a typo? You write empJob -> but your variable is called Jop. So maybe it should be empJop.

String sql = "insert into employee(empid,empName, empAddress,empJop,empSalary) values('" + id + "','" + name + "' , '" + Address + "','" + Jop + "','" + Salary + "')";
wake-0
  • 3,918
  • 5
  • 28
  • 45