Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to everyone. I have a problem about SQL statement in Java, when I clicked on Insert button who contains the code below, threw the following exception: ORA-00933 SQL command not properly ended

I am trying to find out the cause but without result. What going wrong?
Thanks in advance.


public void insertMemberAction() {
String query = "INSERT INTO MEMBERS(MNO, MLASTNAME, MFIRSTNAME, MADDRESS, MREGDATE)"                         + "VALUES('" + jMnoTxt.getText() + "',"
                + "'" + jLastnameTxt.getText() + "',"
                + "'" + jFirstnameTxt.getText() + "',"
                + "'" + jAddressTxt.getText() + "',"
                + "TO_DATE('" + jRegistrationDateTxt.getText() + "','DD/MM/YY'))";

        java.sql.Statement insertStmt;

        try {

            insertStmt = DvdClubJFrame.con.createStatement();
            insertStmt.executeUpdate(query);
            insertStmt.close();

        } catch (java.sql.SQLException e) {
            javax.swing.JOptionPane.showMessageDialog(this, e.getMessage());

        }

    }
Posted
Comments
CHill60 18-Nov-13 18:56pm    
Best suggestion I can give you for an approach to solving this is to capture the content of query and put that directly into your oracle gui/IDE (whatever you can use to run sql queries directly against the database)... you should get the same error. Then remove bits one at a time to determine exactly where the problem lies... I would start with the TO_DATE('jRegistrationDateTxt.getText()','DD/MM/YY') bit
chaau 18-Nov-13 20:23pm    
Please learn about sql injections and how to protect against them. Your code is prone to them. As for your error, it is most likely caused by Scottish surname (like O'Connor, etc) or other strings with single quote (') in them. To fix it you need to add string txt = jLastnameTxt.getText(); txt = replace("'", "''");

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