This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Single Insert Query for Multiple Tables  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code does not compile when I inserted the other tables and Im not really good at SQL statements and such. Is it possible if I can use a single query for inserting into multiple tables?

Code below

 
Rancher
Posts: 3922
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, no.  You can't do mutliple SQL queries in the one Statement.
So your currnet one will need to be split up into three calls, which shouldn't be a major issue?

However.
Since you are using a preparedStatement then you ought to be using it as a PreparedStatament.
At the moment you are simply concatenating the SQL together.

It should take the structure:

and then execute it.
That solves any possible issues with quote characters (for example).  I mean, your current one would fail if Brian O'Neill signed up.

Second point is that this really should not be in a JSP page.
JSP should not have java code in them.
This is something that should be in a servlet or, better, a service class that the servlet calls, which would allow you to test it without all the web server stuff.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, right.

We should use one query per transaction only.

And after each transaction, make practice to close it.
 
Dave Tolls
Rancher
Posts: 3922
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SunilK Chauhan wrote:Yes, right.

We should use one query per transaction only.

And after each transaction, make practice to close it.



Well, not per transaction.
Unless you are using "transaction" to mean something other than a database transaction.
 
Men call me Jim. Women look past me to this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!