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. |
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 ...
|
|||||||
|
|||
|
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
|
| Sponsored Links |
|
|||
|
Re: Where should I write the JDBC code
Quote:
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. |
|
|||
|
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>jdbc dbc:mydsn</param-value></context-param> |
|
|||
|
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.. |
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
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 |