Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4038150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:26:14+00:00 2026-05-20T12:26:14+00:00

I am in the process of designing a simple Java application which deals with

  • 0

I am in the process of designing a simple Java application which deals with insert/delete/update of records in a MySQL database using JDBC. I have a class Member which deals with the member’s details.

class Member {
  ... // Private Members
  ... // Accessors
}

..and I have a handler to deal with the member records

class MemberHandler {
  public MemberHandler(){...}
  public void addMember(Member mem){...}
  public void removeMember(Member mem){...}
  public Member[] getMembers(){...}
}

All I am worried about is the method in which I establish connection to the database and disconnect. I can do it in two ways –

Method 1:
I can have a member in MemberHandler Connection conn, establish connection while instantiating the class and close the connection when the object is no more needed. Here I would have a connection per object and I need not establish a connection whenever I need to do any database related activity. In this case, the disadvantage seems to be – when there is a loss in network connection, conn could become invalid.

class MemberHandler {
  private java.sql.Connection conn;
  ... // Other members
  private void createConnection(){/*creates the connection*/}
  private void closeConnection(){conn.close(); /*called when conn is no more needed*/}
}

Method 2:
I can establish a connection when needed and close it when I am done with the activity. Disadvantage: everytime, I need to establish a connection and close it. For eg.,

...
...
private void addMember() {
  //establish connection
  //update database
  //close connection
}
...
...

Which of these two ways seems to be better? Or is there a third better way?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:26:14+00:00Added an answer on May 20, 2026 at 12:26 pm

    I would suggest you to go for connection-pooling

    • c3po
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of designing a financial web page (using Java, Wicket,
I am in the process of designing a web application which will have multiple
I am in a process of designing a custom SharePoint application. On a previous
I'm in the process of designing part of my companies architecture for its Java
I am in the process of designing and coding an iPhone application to display
I am in the process of designing a web application (really, it's a hobby,
I am currently in the process of designing myself a database driven website. The
I am designing a simple web-based application. I am new to this web-based domain.I
I'm in the process of designing the architecture of an application I’m planning on
We're designing a database that has a simple table called Person. Each person can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.