The moose likes JDBC and Relational Databases and the fly likes MySQLSyntaxErrorException 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 "MySQLSyntaxErrorException" Watch "MySQLSyntaxErrorException" New topic


pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 303
I have this code

and its showing the exception

Afrter this============update job_master jm,job_qualification jq,job_state js,job_location jl SET jm.job_code=?,jm.job_title=?,jm.JOB_DESC=?,jm.JOB_YEAR_OF_EXP=?,jm.JOB_SALARY=?,jm.JOB_COMMENTS=?,jq.QUALIFICATION_ID=?,js.STATE_ID=?,jl.CITY_ID=? where jm.job_id=?
com.mysql.jdbc.exceptions.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 '?,jm.job_title=?,jm.JOB_DESC=?,jm.JOB_YEAR_OF_EXP=?,jm.JOB_SALARY=?,jm.JOB_COMME' at line 1
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.sendCommand(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.ConnectionImpl.execSQL(
at com.mysql.jdbc.StatementImpl.executeUpdate(
at com.mysql.jdbc.StatementImpl.executeUpdate(
at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Please help me.why this coming.

[edit]Add "+" to break long line otherwise it is too long for the width of the screen. CR[/edit]
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Off the top of my head, a couple of problems you might have...

if(job.getStates()!=null && job.getStates().length>0 )
for(i=0; i <job.getStates().length; i++)
psUpdate.setInt(8, job.getStates()[i]);

1) If states() is null, then the statement execution would throw an error.
2) It looks like you are trying to assign multiple values (???), However only the last state would be set. You just are overwriting the values.

This is the same for other if loops.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Yes, as Sridhar says there might be a problem with your code. But if it were me I would take the error message ("You have an error in your SQL syntax") more seriously than that. In that case I would suspect there might be an error in the SQL syntax, and that would lead me to look at the SQL statement.
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
i suspect it may have to do with your attempting a multi-table update but only referencing one of your 4 tables in the where clause of your update statement statement. This would create a cartesian joining all rows in the other three tables to each row selected in your referenced job master table.
I agree. Here's the link:
subject: MySQLSyntaxErrorException
jQuery in Action, 3rd edition