This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Master Rancher
Posts: 3633
40
  • 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
Master Rancher
Posts: 3633
40
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!