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

writing jdbc code once and retrive

 
Praveen Reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my project i have more than 30 JSP pages and for every page i have to connect to database...(some time there is a chance that i may change databases). and i dont want to touch my Business logic, can any one plz give me some coding so that i can write jdbc code once and retrive.

(i know there is some way where we will give class.forname & drivers manager path in Web.xml, if any one know's this plz give me code)


Thnx....in advance
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, keeping database code in JSPs is considered bad design - move any DB access code to Java code, e.g. a backing bean or a servlet. This page of the Tomcat documentation outlines how you can configure and use a connection pool in Tomcat.
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got to give more details like webserver/application server details, database make,ear/war application etc.

Bascially,What you need to do is configure a connection pool and bind it to a Datasource for the specific database, and access it using JNDI in your code.

Read this
 
mitesh mitesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should develop a seperate class for database connection, use when you need it,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic