Click here to Skip to main content
15,897,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the error,
errorcom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Desc,Author) values('jdsaklv','jdskalf','jsdalkf')' at line 1

and here is my code.I am not getting what error is..please help.,


public boolean adddatablog( String name1,String Desc1,String Auth1)
{
boolean result = false;

PreparedStatement psmt=cn1.prepareCall("insert into blog(Name,Desc,Author) values(?,?,?)");
psmt.setString(1,name1);
psmt.setString(2,Desc1);
psmt.setString(3,Auth1);
result=psmt.execute();
return result;

}
Posted
Comments
[no name] 12-Feb-15 1:44am    
Looks like mysql is not happy with "DESC" because it is a reserved word for order by. But if it is like this, how you created the table....?
http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html[^]

Have a look also here, maybe a Workaround available: http://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table[^]
Bruno
Member 11416020 12-Feb-15 2:36am    
Thank you for helping me out bro....

1 solution

Desc is a keyword[^] in MySql. Thus your query fails on the second line.

To fix the problem, escape the column name.
Try "insert into blog(Name,"Desc",Author) values(?,?,?)");
 
Share this answer
 

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