0

I'm currently trying to insert new data into an existing table in my database using embedded SQL. I need to be able to enter my data in a dialog box and then have it shown back to me in a dialog box after it has executed.

My problem seems to be with the "s.executeUpdate(input);" for it tells me that I have an error in MySQL syntax. I'm not really sure how to fix it, or how to change the syntax. Help would be much appreciated!

Connection c = null;
try {

    Class.forName("com.mysql.jdbc.Driver");
    c = DriverManager.getConnection("jdbc:mysql://localhost:3306/company - final project", "root", "");

    String query = "INSERT INTO works_on (ESSN, PNO, HOURS)" + "Values (?, ?, ?)";
    Statement s = c.prepareStatement(query);
    String input = JOptionPane.showInputDialog(null, "Info to be Inserted: ");
    s.executeUpdate(input);
    JOptionPane.showMessageDialog(null, "Data Inserted: " + input);

   c.close();
}
catch (Exception e) 
{
    e.printStackTrace();
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
C. Walker
  • 1
  • 1

1 Answers1

0

You're prepared statement requires 3 parameters, but you did not add any. need to call s.addXXX in the proper order to specify the 3 values to insert, wheres "XXX" is the appropriate type for the values

DBug
  • 2,502
  • 1
  • 12
  • 25
  • So if my values are INT then I would just code s.addInt(); I'm not really sure how to add the parameters. Whenever I code s.addInt it says that it is undefined for the type statement. – C. Walker Nov 22 '15 at 01:21
  • yes, you would use setInt(). Change the type of s from Statement to PreparedStatement. Even though s really is a PreparedStatement, because you declared it as Statement, you can only access the methods defined by Statement. – DBug Nov 22 '15 at 14:19