• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Querying a Database from a session bean using JDBC

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am developing an application that requires the querying of an external database i.e. user requests a number of fields which are stored in the applications database and these are then used to query a second database for the actual values. If anyone can understand what i am talking about, can you direct me as to whats the best approach to doing this. I am using MySQL DB and have been advised to use JDBC in a session bean?

Any ideas?
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fiona,
Basically you have two queries. So the high level approach is:
1) Query external database (database 1)
2) Loop through result set and store fields in variables (or List if multiple rows.)
3) Build sql string for second query. I recommend using prepared statements so you can easily substitute in the values.
4) Run second query (database 2)
5) Loop through result set and process actual values

The logic behind separating the queries is so you can close the first connection sooner. Take a look at Sun's JDBC tutorial to get started with JDBC.

For the future, I recommend posting this type of question in the JDBC forum since it is more about JDBC than session beans.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JDBC...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic