Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Where should I write the JDBC code

This is a discussion on Where should I write the JDBC code within the JSP forums, part of the Web Development category; 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 ...

Go Back   Geeks Talk > Web Development > JSP
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

JSP JSP Related Issues and Problems

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-05-2007
Junior Member
 
Join Date: Jan 2007
Location: Hyderabad
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
chandu_7k is on a distinguished road
Where should I write the JDBC code

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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-07-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 9 Times in 8 Posts
vmshenoy is on a distinguished road
Re: Where should I write the JDBC code

Quote:
Originally Posted by chandu_7k View Post
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
You can create a Connection Class, keep one getConnection method there which has JDBC code and
whenever u want to create a connection then make object of that class
and call that function.

If you are going for big projects then you can use connection pooling!

thanks
__________________
:)
NEVER SAY DIE.
Reply With Quote
  #3 (permalink)  
Old 04-10-2007
Junior Member
 
Join Date: Dec 2006
Location: bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
leelavish is on a distinguished road
Re: Where should I write the JDBC code

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
<context-param>
<param-name>url</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
<param-name>connstring</param-name>
<param-value>jdbcdbc:mydsn</param-value>
</context-param>
Reply With Quote
  #4 (permalink)  
Old 04-16-2007
Junior Member
 
Join Date: Nov 2006
Location: India
Posts: 8
Thanks: 0
Thanked 2 Times in 2 Posts
madhukar.poreddy is on a distinguished road
Re: Where should I write the JDBC code

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..
Reply With Quote
  #5 (permalink)  
Old 06-15-2007
Junior Member
 
Join Date: Apr 2007
Location: Chennai
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
vinotha is on a distinguished road
Re: Where should I write the JDBC code

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 08:17 AM.
Reply With Quote
  #6 (permalink)  
Old 06-19-2007
Junior Member
 
Join Date: Jun 2007
Location: Bengalore
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
v.chennas is on a distinguished road
Re: Where should I write the JDBC code

how to configure the jdbc in weblogicserver
Reply With Quote
  #7 (permalink)  
Old 06-19-2007
Junior Member
 
Join Date: Apr 2007
Location: Chennai
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
vinotha is on a distinguished road
Re: how to configure the jdbc in weblogicserver

hi,

for JDBC COnnection in WebLogic,

go to Services,

First set Connection Pool and then Set DataSource.
Reply With Quote
  #8 (permalink)  
Old 07-04-2007
Junior Member
 
Join Date: Dec 2006
Location: India
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kezhilnambi is on a distinguished road
Re: Where should I write the JDBC code

try to use DAO s
Reply With Quote
Reply

  Geeks Talk > Web Development > JSP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Write an SQL query JobHelper SQL 2 09-22-2008 09:35 AM
Need to write into word document through VB.NET Geek_Guest VB.NET 0 02-24-2007 05:54 AM
how should we write the script? abraham_ahmed Testing Issues 4 02-15-2007 05:05 AM
Types of JDBC Deriver Managers timmy Java 1 07-17-2006 05:12 PM
The Read/Write Web Lokesh M HTML & CSS 0 06-21-2006 12:58 AM


All times are GMT -4. The time now is 04:00 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved