• 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

SQL syntax error

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Donna, you cannot insert into two tables. Or rather, I know of no database that supports such action.
You have to break the statement.
 
Donna Harrington
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I broke it into 2 statements. Thanx very much for yer help! appreciate yer comments!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic