If we have 10 servlets, and we need to use database connection. Then Where should I write the JDBC code that must be established from a servlet and need to utilize in all other servlets
If we have 10 servlets, and we need to use database connection. Then Where should I write the JDBC code that must be established from a servlet and need to utilize in all other servlets
:)
NEVER SAY DIE.
Write a separate java class with the static getConn() method. u can get the connection object by Connection con = MyConnection.getConn()
or
use context param in deployment descriptor file(web.xml) outside all servlet tags add the details about ur database later get the parameter values in init() using getInitParameter()
here is the sample code
url
sun.jdbc.odbc.JdbcOdbcDriver
connstring
jdbcdbc:mydsn
Do one thing write a simple java class and put all the JDBC code and use the class in servlets where u want.
if you are using the application Servler better to use the Connection Pooling which ipmroves the performance of the application.
It may helps you..
Thanks..
Hi,
use a seperate class which makes JDBC Connection.
then call that class from all other servlets which needs to access database
Last edited by vinotha; 06-19-2007 at 07:17 AM.
how to configure the jdbc in weblogicserver
hi,
for JDBC COnnection in WebLogic,
go to Services,
First set Connection Pool and then Set DataSource.
try to use DAO s