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 7781373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:12:30+00:00 2026-06-01T19:12:30+00:00

I want to use Connection pooling in my java web application with MySQL and

  • 0

I want to use Connection pooling in my java web application with MySQL and JDBC, I found a very resource to learn at Apache Tomcat 6.0 (6.0.35) – JNDI Datasource HOW-TO,
But this example uses JSTL code to explain how to retrieve connection from pool. I want to work similarly but with a MVC architecture from scratch consisting of Beans, DAOs, Servlets and JSPs. I got everything I want from a very good DAO tutorial by BalusC but I am confused in the last part of tutorial saying How about Connection Pooling?. Could anyone please elaborate on this connection pooling topic and the close() method?

EDIT:
Actually i should have add this thing earlier also:
As the tutorial I have linked above comes before JDK7, which now has try-wth-resource code that closes the Connection automatically, then how can we maintain a Connection pool and closing a Connection in pool here with the same DAO code (or with few changes) as in the tutorial?

  • 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-06-01T19:12:32+00:00Added an answer on June 1, 2026 at 7:12 pm

    if your application requires is to be used by several users one connection can be held by a connection pool so several of those users will reuse the existing connection instead of making new connection which will consume time.
    about the close()method: the connection pool stays active and if you do not close a connection to it after every access,connections will pile up and if the number increases the connection pool get jammed and no longer accepts other connections!

    public class MyDao {
    
        private InitialContext context;
        private DataSource datasource;
    
        public MyDao() {
    
            try {
    
                Class.forName("com.mysql.jdbc.Driver");
                Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "username", "password");
                context = new InitialContext();
                datasource = (DataSource) context.lookup("datasource name");
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.getMessage());
            }
    
        }
     public MyBean getMyBean() throws SQLException {
            Connection connection = null;
            PreparedStatement statement = null;
            ResultSet res = null;
    
            String sql = "some query";
            try {
                connection = datasource.getConnection();//pool connection
                statement = connection.prepareStatement(sql);
                res = statement.executeQuery();
                while (res.next()) {
                   //return true
    
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
    
         finally {
                if (rs!= null) try { rs.close(); } catch (SQLException logOrIgnore) {}//result set if any
                if (stm!= null) try { stm.close(); } catch (SQLException logOrIgnore) {}//clase statement if any
                if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}//close connection
                }
                }
    
    
    }//close MyDao
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a java web Application and I use Tomcat connection pooling, here
I want to use connection pool with JPA/TopLink in my web app running on
I want to use connection pooling with Jetty 6 , but so far it
I want to use a JDBC connection pool. The most important factor is that
I've been trying to implement connection pooling for my application using Apache HTTPClient (v4.1).
I want to use pooled connections with Java (because it is costly to create
i want use some data from a website with web service. i have a
I want use JQuery mobile for the front-end of my mobile application, but I
I want to use the connection string App.Config file. Also is it possible to
I learnt about prepared statements when making a JDBC-enabled Java application, and my app

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.