Results 1 to 8 of 8

Thread: Where should I write the JDBC code

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Answers
    2

    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


  2. #2
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    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.

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Answers
    1

    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

    url
    sun.jdbc.odbc.JdbcOdbcDriver
    connstring
    jdbcdbc:mydsn



  4. #4

    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..


  5. #5
    Junior Member
    Join Date
    Apr 2007
    Answers
    15

    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 07:17 AM.

  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    1

    Re: Where should I write the JDBC code

    how to configure the jdbc in weblogicserver


  7. #7
    Junior Member
    Join Date
    Apr 2007
    Answers
    15

    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.


  8. #8
    Junior Member
    Join Date
    Dec 2006
    Answers
    2

    Re: Where should I write the JDBC code

    try to use DAO s


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact