• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Methods for using JDBC Class in a web app?

 
Nate Leech
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic