• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MySQLSyntaxErrorException

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

>
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic