无法将数据插入数据库(语法错误进入INSERT INTO语句)

时间:2013-07-02 16:06:32

标签: java syntax syntax-error

private void addCustomerActionPerformed( ActionEvent e )
{   
   String Query;
   Query = "INSERT INTO Membership VALUES"+ "(' " +memberID_a.getText() + " ' , ' " +memberName_a.getText() + " ' , ' " + icNo_a.getText()  + " ', ' " + gender_a.getText()  +" ' , '" + birthday_a.getText()  +" ' , ' " + telephoneNo_a.getText()  + " ',' " + mobileNo_a.getText()  + " ' , ' " + email_a.getText()  + " ' , ' " + address_a.getText()  + " ' , " + postalCode_a.getText() + " ,' " + state_a.getText()  + " ' , '" + country_a.getText()  + " ' , " + memberPoint_a.getText() + ");";


       try {

           stmtInsert = conn.createStatement(); 
           stmtInsert.executeUpdate(Query);


        } catch(Exception ex){
             JOptionPane.showMessageDialog(null,"ERROR"+ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
        }
   } 

我收到错误

  

java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序] INSERT INTO语句中的语法错误。

有人帮我解决这个问题吗?感谢

1 个答案:

答案 0 :(得分:0)

这将有效

Query ="INSERT INTO Membership VALUES ( " +memberID_a.getText() + " , " +memberName_a.getText() + " , " + icNo_a.getText()  + " , " + gender_a.getText()  +" ," + birthday_a.getText()  +"," + telephoneNo_a.getText()  + " , " + mobileNo_a.getText()  + " , " + email_a.getText()  + " , " + address_a.getText()  + " , " + postalCode_a.getText() + ", " + state_a.getText()  + " ," + country_a.getText()  + "," + memberPoint_a.getText() + ")";