It's not a secret anymore!*
The moose likes JDBC and the fly likes writing jdbc code once  and retrive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "writing jdbc code once  and retrive " Watch "writing jdbc code once  and retrive " New topic
Author

writing jdbc code once and retrive

Praveen Reddy
Ranch Hand

Joined: Jul 12, 2006
Posts: 51
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
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
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

Joined: Nov 06, 2002
Posts: 239
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


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
mitesh mitesh
Greenhorn

Joined: Jul 12, 2006
Posts: 2
you should develop a seperate class for database connection, use when you need it,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing jdbc code once and retrive