i'm not too familiar with java...though...
actually i'm trying to insert the values entered by the user into the access table but every time i click the add button on my application it shows java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
error...

String str="insert into books(ISBN,Title,Edition,Category,Author,Desc) values('";
                str+=isbnField.getText();
                str+="','";
                str+=titleField.getText();
                str+="','";
                str+=editionField.getText();
                str+="','";
                str+=categoryField.getText();
                str+="','";
                str+=authorField.getText();
                str+="','";
                str+=descArea.getText();
                str+="')";
                try
                    {
                    stmt11.execute(str);
                    }catch(Exception ea1)
                    {ea1.printStackTrace();}

would be a great help.....:)

Print out 'str' just before you execute it. The error message says you have a syntax error in the SQL statement. It's not a java issue.

hi,
thnx for reply..
after i printed 'str', it executed the sql command in proper format...
then also i couldn't find the solution...
the command is....

insert into books(ISBN,Title,Edition,Category,Author,Desc_book) values('1000','nokia','5th','mobile','nokia company','nice company');

thnx

I'm having the same problem. i have printed the SQL string and the syntax seems correct to me. Could the problem be located outside of Java maybe in the database driver?

I'm having the same problem. i have printed the SQL string and the syntax seems correct to me. Could the problem be located outside of Java maybe in the database driver?

A new thread by you, with your code and the error merssage, would be helpful

Im sorry that this is so late, but since google is still pointing to the thread, I thought I should post the answer. The SQL INSERT command goes INSERT INTO <tablename> VALUES (value1, value2..), so the problem is that the syntax of the insert command you are using is wrong. This would work:

String str="INSERT INTO books VALUES('";
                str+=isbnField.getText();
                str+="','";
                str+=titleField.getText();
                str+="','";
                str+=editionField.getText();
                str+="','";
                str+=categoryField.getText();
                str+="','";
                str+=authorField.getText();
                str+="','";
                str+=descArea.getText();
                str+="')";
stmt11.execute(str);

Edited 5 Years Ago by FumblingFool: n/a

Not only is it late, it's not the solution.

It's perfectly valid to specify the insert fields as well as the values

INSERT INTO <tablename>(field1,field2..) VALUES (value1, value2..)
This article has been dead for over six months. Start a new discussion instead.