• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp and database

 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respected Sirs,
Which is the best place to write databse connection code when developing web application.Can I write it in a single file and use it in all pages?

Regards Francis.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not write this in all your pages. It's time consuming, and simply not cool
You should use connection pooling. There are many utilities for this, like the one by Jakarta, or make your own wrapper class.

http://jakarta.apache.org/commons/dbcp/
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it should be done on single file so it can be centralized.. once you make changes to your connection it can easily be done because you only need to change the codes of a single file
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by francis varkey:
Which is the best place to write databse connection code when developing web application.Can I write it in a single file and use it in all pages?


I would also say, yes. But make sure that file should not be a JSP page nor a servlet. It can be a simple/normal old java class.

Using conection pool is a better option, I must say.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!