Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
st.executeUpdate("INSERT INTO studdet ( NAME, EMAIL,phoneno,adress )values ('+name+','+email+',+ph+,'+ad+')");


com.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 ''+ad+')' at line 1
Posted

It looks like you have a few problems here. The first is one of spelling. I think you might have spelled the names in your query wrong (studdet instead of student, adress instead of address, etc.) Check there first.

Next, it looks like the values you are inserting are variables but you are not properly escaping them from the string. This is how you should do it:
Java
st.executeUpdate("INSERT INTO studdet ( NAME, EMAIL,phoneno,adress )values ('"+name+"','"+email+"',"+ph+",'"+ad+"')");

Notice the double-quotes to escape the string and allow the variable to be accessed properly.

As a side note, I would recommend that you not put variables directly into a SQL statement until you have first verified that they are "clean" (no special characters that could lead to a SQL Injection attack).
 
Share this answer
 
Comments
AshishChaudha 28-Jun-12 9:42am    
good answer..my 5!
inserting values in string must be enclosed in '"+ yourvariable +"'

so try as follows:

SQL
values ('"+name+"','"+email+"',+ph+,'"+ad+"')");



make it answer if you got your solution...

Thanks
 
Share this answer
 
Are you sure its adress and not address?
 
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