Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic question

 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can someone help me with the problem Im having. I dont know how to do a class that takes care of creating database connection. For example if db changes I have to do changes only in one place instead all the places where I created connection.
Please help?
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advise is that you use connection pooling. for instance, www.javaexchange.com. And yes, it is for free.
with javaexchange you specify in a single servlet the database you are going to use, minimum number of connections, maximum number of connection, etc.
in other words, it acts as a broker. You just make use of the connection and free them when you are done.
in this way if you change your database you only change the database name and the driver (if you need to change it) in a single place.
cheers
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andres,
but if I understand correctly I need to have a server to run servlet? I guess what I need is some sort of class doing

and whenever I need to have a connection it is created like

but that doesnt work :/
[ June 16, 2002: Message edited by: Martin Schneider ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hhhmm... I did not quite understand what you meant Martin. The code you posted is done internally by the class you download from javaexchange.

but if I understand correctly I need to have a server to run servlet?


I use Forte for java, but you can also use tomcat, if this is your question...
I do not have the code here in this PC, but if you requiere so more in-depth example let me know.
cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic