aspose file tools*
The moose likes JDBC and the fly likes SQL syntax error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL syntax error" Watch "SQL syntax error" New topic
Author

SQL syntax error

Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
Hey all,
I have a syntax error and i want to update both tables customerdetails table and order table. but my join is wrong or something. can anybody see my error. thank u!
PreparedStatement p = con.prepareStatement("INSERT INTO customerdetails JOIN order(Title,Username,Password,FirstName,Surname,Address,City,Email,TelephoneNum,cardType,cardNum,date,month,year,shipTitle,shipSurname,shipAddress,shipCity,shipCountry,shipPostalCode)"+" VALUES('"+radio+"','"+Username+"','"+Password+"','"+FirstName+"','"+Surname+"','"+Address+"','"+City+"','"+Email+"','"+telephoneNum+"','"+radio1+"','"+cardNum+"','"+date+"','"+month+"','"+year+"','"+radio2+"','"+shipName+"','"+shipSurname+"','"+shipAddress+"','"+shipCity+"','"+shipCountry+"','"+shipPostalCode+"')");
p.executeUpdate();
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
I think you're problem is the JOIN on the insert. I don't know of any database that would support that. You've got to break it down into two separate insert statements, one per table. If they need to be done as a whole, then you'll need to enclose them in a transaction and do a commit or rollback. Also, if you're going to use prepared statements, you should look at how to use them. When using the (?, ?, ?, ...) form that prepared statement allow, you get the benefit of not having to deterime whether the parameter will require single quotes or not.
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Donna, you cannot insert into two tables. Or rather, I know of no database that supports such action.
You have to break the statement.


SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
I broke it into 2 statements. Thanx very much for yer help! appreciate yer comments!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL syntax error