• 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

Methods for using JDBC Class in a web app?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first time using JDBC and I am having a hard time firguring out the best way to implement my SQL queries in my web app.

Right now I have one class called DataBaseMethods

In this class, I have one method for each call to the database I make.

getChildren();
getPersonIds();
.
.
.
etc...

In each method, I open the database connection, make and execute the sql query and then close the database connection.

I then call these methods in my other buisiness logic classes.

I think this would end up making a LOT of opening and closing of the db. Is there a better way to do this?

Thanks for any help!!!

-Nate
 
author & internet detective
Posts: 41860
908
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
Nate,
There is nothing inherently wrong with opening/closing connections. As you run more queries and have multiple users, you can look into connection pooling. The application server provides this. You just get your connection from a datasource in the JNDI instead of using driver manager. Then you aren't really closing the connection, you are just putting it back in the pool. Also, doing one query at a time gives you a better design for the future.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic