Results 1 to 4 of 4
  1. #1
    mvidal is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default SQL - Syntax error in UPDATE statement

    That is the error messange - java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement

    Java Code:
    String charger="0";
                String battery="0";
                String cable="0";
                String carry="0";
                
                String date = dateText1.getText();
                String name = nameText1.getText();
                String cccNumberCust = CCCNumberCustText1.getText();
                String title = titleText1.getText();
                String department = departmentText1.getText();
                String phone = phoneText1.getText();
                String room = roomText1.getText();
                String technician = technicianText1.getText();
                String cccId = idText1.getText();
               
                if(chargerCustCheck1.isSelected()) {
                    charger = "1";
                }
                if(batteryCustCheck1.isSelected()) {
                    battery = "1";
                }
                if(cableCustCheck1.isSelected()) {
                    cable = "1";
                }
                if(carryCustCheck1.isSelected()) {
                    carry = "1";
                }
                            
                //The problem is HEREEEEEEEeeee, and I have no idea WHY.
                int x = st.executeUpdate("UPDATE Customer set CCCid='"+cccId+"', Date='"+date+"', CCCNumberCust='"+cccNumberCust+"',"
                        + "Name='"+name+"', Title='"+title+"', Department='"+department+"', Phone='"+phone+"',"
                        + "Room='"+room+"', Technician='"+technician+"', Charger='"+charger+"', Battery='"+battery+"',"
                        + "Cable='"+cable+"', Case='"+carry+"', where CCCid='"+cccId+"'");
         
                System.out.print("Right HERE!!");//The code jump this print and go to Exception
                
                JOptionPane.showMessageDialog(null, "Customer Updated in the DataBase!!");

  2. #2
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: SQL - Syntax error in UPDATE statement

    My advice: use a PreparedStatement. Amongst other things, it will help you actually see the syntax of your query, helping you spot any glaring errors

  3. #3
    mvidal is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: SQL - Syntax error in UPDATE statement

    That is my connection. After I chance to PreparedStatmente, a lot of things in my code stopped to work.

    Error message:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcStatement cannot be cast to java.sql.PreparedStatement
    at OitProjectPackage.oitFrame.conexao(oitFrame.java:2 9)
    at OitProjectPackage.oitFrame.updateCustRegActionPerf ormed(oitFrame.java:2200)
    at OitProjectPackage.oitFrame.access$3400(oitFrame.ja va:13)
    at OitProjectPackage.oitFrame$38.actionPerformed(oitF rame.java:1585)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    * it has a lot more.

    //Objeto de banco
    Connection con = null;
    Statement st = null;

    //metod para fazer a conexao de banco
    public void conexao()
    {
    try {
    //1 passo - carregar o driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //2 passo - criar a conexao de banco
    con = DriverManager.getConnection("jdbc:odbc:DNShwc");

    //3 passo - criar o obejto que manipula a rotina sql
    st = con.createStatement();

    } catch (ClassNotFoundException | SQLException e) {

    }
    }

  4. #4
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: SQL - Syntax error in UPDATE statement

    Based upon the exception it seems you are trying to cast a Statement to a PreparedStatement - see Using Prepared Statements (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics) That's the advice I can provide based upon what you posted, because the Exception you posted does not seem as though it would originate from the code in your last post.

Similar Threads

  1. Syntax error in If statement
    By robinsonth@gmail.com in forum New To Java
    Replies: 2
    Last Post: 11-08-2012, 10:38 AM
  2. Syntax error in UPDATE statement Need Help!
    By mathidioticz in forum New To Java
    Replies: 7
    Last Post: 01-21-2012, 06:48 PM
  3. error while using sql update statement
    By jttslg in forum Advanced Java
    Replies: 14
    Last Post: 07-03-2011, 10:38 PM
  4. Syntax of Switch statement in j2me
    By jprgmr75 in forum CLDC and MIDP
    Replies: 0
    Last Post: 01-03-2011, 05:49 PM
  5. Java Syntax If statement
    By Blasz in forum New To Java
    Replies: 9
    Last Post: 09-01-2010, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •