File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes error in update query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "error in update query" Watch "error in update query" New topic

error in update query

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I am getting a variable in a string like


But if i try to store the state in the database like

I am getting the following error:

java.sql.SQLException: Syntax error or access violation message from server: "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 'Dialing''' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.sendCommand(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.MysqlIO.sqlQuery(
at com.mysql.jdbc.Connection.execSQL(
at com.mysql.jdbc.Connection.execSQL(
at com.mysql.jdbc.Statement.executeUpdate(
at com.mysql.jdbc.Statement.executeUpdate(
at com.example.servlets.Call2.doGet(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
at org.apache.tomcat.util.threads.ThreadPool$

Here extnum is the variable i got from the table contacts in the database people .

I dont know why it happens?Any help would be appreciated

Swastik Dey

Joined: Jan 08, 2009
Posts: 1578

What is the datatype of extnum in your table?

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use PreparedStatement all the way. It not only eases setting non-standard typed Java objects in your SQL, but it also saves you from SQL injection attacks and singlequote headaches.

Prepare here:
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you for your replies.I will try to use prepared statement. Then the datatype of extnum is varchar
I agree. Here's the link:
subject: error in update query
It's not a secret anymore!