File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "MySQLSyntaxErrorException" Watch "MySQLSyntaxErrorException" New topic
Author

MySQLSyntaxErrorException

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 301
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

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
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

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: http://aspose.com/file-tools
 
subject: MySQLSyntaxErrorException