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

  • Home
  • SEARCH
  • 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 466467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:28:59+00:00 2026-05-12T23:28:59+00:00

This might sound like a noob question but this is the first time I’m

  • 0

This might sound like a noob question but this is the first time I’m treading into Database territory.
From here I got the info that

The most efficient way to implement
communication between the server and
database is to set up a database
connection pool. Creating a new
connection for each client request can
be very time-consuming, especially for
applications that continuously receive
a large number of requests.

and the tutorial uses a JNDI datasource.

My application is also similar(but I won’t be using Tomcat, just sockets) and my server will be getting requests from multiple clients but I don’t understand why should I use a JNDI datasource, why can’t the server maintain one open connection with the Database and when a client request arrives it will process the request and feed the data to the client.

In the worst case, If I should need a JNDI how can I implement it with my server app?

  • 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-12T23:29:00+00:00Added an answer on May 12, 2026 at 11:29 pm

    Thus, it is a client application? The application and the database usually talks with each other using a connection obtained by DriverManager#getConnection()? If so, then you don’t necessarily need JNDI to get connection pooling to work. Alone the connection pooling framework in question would already suffice. For example C3P0 or Apache Commons DBCP (I would recommend C3P0; DBCP is singlethreaded). Just replace the DriverManager#getConnection() by it.

    Edit: reply on your comments:

    The server would be talking to the database and the clients connect to the server, so I won’t know whether to call this a client application.

    I actually mean, a plain vanilla Java application which doesn’t run inside a Java EE container. Pascal has worded it better.

    Actually I’m a bit confused about how connection pooling works, does each connection run in its own thread? is there any document/book to help me get a better understanding of these concepts vis-a-vis a non pooled connection?

    To start, the connection pool opens a connection and holds it open as long as up to the configured timeout. The connection pool wraps/decorates the connection with its own implementation. The connection pool can open and hold a configured amount of connections simultaneously. When you call getConnection(), it will immediately give you an already opened connection. When you call close() on the connection, it will put the connection back in the pool for future requests. This thus means that you still have to write the JDBC code the usual way: acquire and close the Connection, Statement and ResultSet in the shortest possible scope. Close them all in the finally block. If your JDBC code is already well written, in fact only the DriverManager#getConnection() needs to be replaced. As you ought to open and close the Connection in the very same method block, it will normally run in the same thread. The connection pooling will worry about that the Connection is not acquired by another threads in the meanwhile until your code calls close() on the Connection.

    You can find here a nice article to get the idea how connection pooling works under the hood (take care: don’t use it for production and don’t homegrow it further, it is just to get the whole idea). For real work, use an existing thoroughly developed and robust connection pooling framework.

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

Sidebar

Related Questions

This might sound like a noob question, but are: string var; if (var ==
This might sound like a noob question, but here it goes anyway. Can BlackBerry
this may sound like a strange question from a Python noob, but here's the
This might sound like a little bit of a crazy question, but how can
This might sound like a stupid question, but google didn't help me. Is there
This might sound like a reaaaally dumb question but... why do browsers have a
I know this question might sound a little cheesy but this is the first
This might sound like a very stupid question to some of you, but I
This might sound like a silly question but is there a manual or a
HI, this might sound like a silly question but.. i've created several types in

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.