Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I am trying to insert data into a mysql database table I got the following error "Syntax error in your mysql statement near Values(". I don't know how to fix this matter. The source code is stated at the below.

If you could please solve my problem!

Thank You.


Java
 private void cmdAddDataActionPerformed(java.awt.event.ActionEvent evt) {
       // TODO add your handling code here:

       String ItCode = txtICode.getText();
       String ItType = txtIType.getText();
       int ItSize = Integer.parseInt(txtISize.getText());
       String ItName = txtIName.getText();
       String ItColour = txtIColor.getText();
       int InStock = Integer.parseInt(txtIStock.getText());
       double ItPrice = Double.parseDouble(txtIPrice.getText());



       conn = DbConn.ConnDB();
       String sql;
       sql = "INSERT INTO ITEMDETAILS("
+ "ItemCode,"
+ "ItemType,"
+ "ItemSize,"
+ "ItemName,"
+ "ItemColour,"
+ "InStock,"
+"ItemPrice)
VALAUES('" + ItCode + "','" + ItType + "'," + ItSize +",'" + ItName + "','"+ ItColour +"'," + InStock + ",'"+ ItPrice + "');



        try {
           ps = conn.prepareStatement(sql);
           ps.execute();
           JOptionPane.showMessageDialog(null, "Saved");
           UpdateJTable();
           //conn.close();
       } catch (Exception e) {
           JOptionPane.showMessageDialog(null, e);
       }



   }
Posted
Updated 5-Jan-13 0:39am
v2

Hi,

Incorrect spell
Quote:
VALAUES

it should be values.

best luck
 
Share this answer
 
Comments
Chiranthaka Sampath 5-Jan-13 9:29am    
Now I am getting an error "unclosed character literal not a statement unclosed string literal". Could you please solve this also?
The Correct MySQL statement is at below.
Java
sql = "INSERT INTO ITEMDETAILS("
 + "ItemCode,"
 + "ItemType,"
 + "ItemSize,"
 + "ItemName,"
 + "ItemColour,"
 + "InStock,"
 +"ItemPrice)" + "VALUES(" + txtICode.getText() + ",'" + txtIType.getText() + "','" + txtISize.getText() + "','" + txtIName.getText() + "','"+ txtIColor.getText() + "','" + txtIStock.getText() + "','" + txtIPrice.getText() + "')";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900