Results 1 to 4 of 4
  1. #1
    onlysumitg is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Question JDBC Connection...

    Hello All

    For a Database application should i use a single Connection/Statement object for all database operation or should i create new Connection/Statement object for each database query ?

    thanks in Advance
    Sumit

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    Hi,
    You can use a method for creating the connection as well as for statement object.U can resuse it .After using ,make sure to close statement,ResultSet and connection to avoid memory leaks.
    -Regards
    Ramya
    Ramya:cool:

  3. #3
    onlysumitg is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    thanks for your reply....

    i wanna know should i call that method again and again to create Connection/Statement objects ... of should i call that once when user login and close that Connection when log off...?

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    Ur code flow will be like this.Connection should not be created and closed multiple times.Declare the Connection object globally open once and close once.

    1. Open the Connection for ex: using openConnection() method

    2. Do database operations

    3. Close the connection for ex: using closeConnection() method
    Ramya:cool:

Similar Threads

  1. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 08:37 AM
  2. Problem in jdbc connection with servlets
    By illusion1912 in forum Java Servlet
    Replies: 0
    Last Post: 01-06-2009, 07:34 PM
  3. jdbc connection problem
    By Assaf A in forum JDBC
    Replies: 0
    Last Post: 12-01-2008, 05:08 PM
  4. JDBC connection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-10-2007, 07:39 PM
  5. How to close JDBC Connection
    By Heather in forum JDBC
    Replies: 2
    Last Post: 07-15-2007, 01:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •