Reputation: 3
I wrote a query
sql = "INSERT INTO TABLE(COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) " +
"VALUES('" + VAR1+ "','" + VAR2 + "','" + VAR3 + "','" + " '" + VAR4 + "','" + "VAR5 + );";
where var5
is a string.
When I try to insert into table and use above SQL I get the error
java.sql.SQLSyntaxErrorException: ORA-00917 : no comma
Where is the mistake?
Upvotes: 0
Views: 66
Reputation: 5609
You had the quotes wrong:
sql = "INSERT INTO TABLE(COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) " +
"VALUES('" + VAR1 + "','" + VAR2 + "','" + VAR3 + "','" + VAR4 + "','" + VAR5 + ");";
The quote next to last must be placed between the plus and the parenthesis, not before VAR5. Also you doubled the single quote before VAR4 (credit to DevilsHnd).
Upvotes: 1
Reputation: 35920
Your single and double quotes around VAR5
was not correct and also you don't need ;
in the string:
sql = "INSERT INTO TABLE(COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) " +
"VALUES('" + VAR1+ "','" + VAR2 + "','" + VAR3 + "','" + " '" + VAR4 + "','" + VAR5 + "')";
Upvotes: 0
Reputation: 3
Thanks for your help
The right syntax is:
sql = "INSERT INTO TABLE(COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) " +
" VALUES('" + VAR1+ "','" + VAR2+ "','" + VAR3+ "','" + VAR4+ "','" + VAR5+ "')";
Upvotes: 0