• 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

Single Insert Query for Multiple Tables

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic