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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:05:31+00:00 2026-05-23T14:05:31+00:00

I have to implement a connection pool along with the standard JDBC DAO with

  • 0

I have to implement a connection pool along with the standard JDBC DAO with an SQLite database. What are the simplest options to implement a connection pool that will reuse the database connections to reduce overhead of the web application? Here is what I have coded:

package persistance;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLite {

    Connection conn = null;
    Statement stat = null;

    public SQLite(String path) {
        String dbPath = path + "GTI525.db";
        System.out.println(dbPath);
        try {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:" + dbPath);
            stat = conn.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public ResultSet query(String sql) {
        ResultSet rs = null;
        try {
            rs = stat.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
}
  • 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-23T14:05:31+00:00Added an answer on May 23, 2026 at 2:05 pm

    As others have mentioned, there are a number of prebuilt solutions that you might want to consider.

    However, if you want the simplest possible custom pool implementation, you could use a circular array of some reasonable size, like 100. Then just populate it with SQLite objects and place some arbiter in front of it that hands queries out to the objects in the array. Something like:

    public ResultSet runQuery(String sql) {
        SQLite connection = null;
    
        synchronized(this) {
            connection = connectionArray[currentIndex];
            currentIndex++;
            if (currentIndex >= connectionArray.length) {
                currentIndex = 0;
            }
        }
    
        return connection.query(sql);
    }
    

    In practice, however, there is little sense in allocating and opening 100 connections until the application actually needs that many. As such, you would probably want to, at a minimum, add an isBusy() method to your SQLite class, and implement your arbiter class such that it searches for the first SQLite that is not bust and uses that one, allocating a new one only when all the existing instances are busy (and only if there is still space in the array for a new one).

    You may also want your SQLite class to verify that the connection is still open in query(), as most databases will close a connection if it sits idle for too long. And this is something that is bound to happen at least occasionally in your connection pool.

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

Sidebar

Related Questions

I'm trying to implement persistent database connection pool with django. One of the options
I have a security consultant demanding that we implement encrypted connections to mySQL. He
I have found that I often have to implement some sort of a scheduler
Let's say I have to implement a piece of T-SQL code that must return
I am trying to implement jdbc-pool in a standalone web app (self contained -
I have an application that is already using the Spring Framework and Spring JDBC
I have a scenario that I need to implement. Namely, my server needs to
I use HSQLDB and Hibernate. I have to implement some functionality on database level
I have to implement .net assembly that would be put into GAC. It relies
I have been trying to implement a webDAV connection on an existing IIS ASP.NET

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.