Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQLSyntaxErrorException

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1605)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1524)
at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
at com.consulting.dao.JobDBdao.update(JobDBdao.java:273)
at com.consulting.action.JobAction.update(JobAction.java:152)
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic