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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:50:09+00:00 2026-06-12T16:50:09+00:00

I have this problem with c3p0 connection pooling, i am new with c3p0. My

  • 0

I have this problem with c3p0 connection pooling, i am new with c3p0.

My desktop program use java with mssql 2008r2
the jdbc driver i use is jtds
and for the connection pooling i use c3p0

i have some problem when the program is running for some time, the program is stuck because it is waiting to get connection from the pool.

it seems that the connection pool is full, so that the sql statement cannot be executed.
i already close the connection every time i have finished execute the sql statement.

does anyone having this same problem with c3p0 ?

note :
i use ComboPooledDataSource and when i want to get some connection, i use the ComboPooledDataSource, getConnection() method. this getConnection() method from ComboPooledDataSource, does it get the idle connection?

how to make connection to idle? because i already close the connection everytime i get the connection.

Thanks.

here’s the code i use:
generally i have 2 class:
1.for the database connection (to get connection and the pooling)
2.for the database transaction (to execute query statement)

public final class DBConnection {
private static DatabaseProperties dbProp;
private static ComboPooledDataSource ds;

private DBConnection(){}

private static void create(){
    DatabaseProperties dp = getDatabaseProperties();
    boolean success = true;

    do{
        try{
            ds = new ComboPooledDataSource();
            ds.setDriverClass("net.sourceforge.jtds.jdbc.Driver");
            ds.setJdbcUrl("jdbc:jtds:sqlserver://"+ dp.getIpaddr()+":"+dp.getPort()+ "/"+dp.getDbname(););
            ds.setUser(dp.getUsername());
            ds.setPassword(dp.getPassword());

            ds.setMinPoolSize(3);
            ds.setAcquireIncrement(1);
            ds.setMaxPoolSize(20);
        } catch (Exception ex) {
            LoggerController.log(Level.SEVERE,"Database error on creating connection",ex,LoggerController.DATABASE);
            success = false;
        }
    }while(!success);
}
public static ComboPooledDataSource getDataSource(){
    if(ds == null)create();

    return ds;
}

public static Connection getConnection(){
    Connection con = null;
    try {
        con = DBConnection.getDataSource().getConnection();
    } catch (SQLException ex) {
        LoggerController.log(Level.SEVERE,"Database error on getting connection",ex,LoggerController.DATABASE);
    }

    return con;
}

public static void close(){
    ds.close();
}

}

public class DBTrans {
private DBTrans(){}

public static DataTable executeQuery(String query) throws SQLException{
    DataTable dt = null;
    Connection con = null;
    try {
        con = DBConnection.getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        dt = new DataTable(rs);
    } catch (SQLException ex) {
        throw new SQLException("QUERY= ["+query+"]\n"+ex.getMessage());
    }
    finally{
        if(con!=null){
            con.close();
        }
    }
    return dt;
}

public static int executeUpdate(String query) throws SQLException{
    int sql = 0;
    Connection con = null;
    try {
        con = DBConnection.getConnection();
        Statement stmt = con.createStatement();
        sql = stmt.executeUpdate(query);
        con.close();
    } catch (SQLException ex) {
        throw new SQLException("QUERY=["+query+"]\n"+ex.getMessage());
    }
    finally{
        if(con!=null){
            con.close();
        }
    }
    return sql;
}

}

  • 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-12T16:50:11+00:00Added an answer on June 12, 2026 at 4:50 pm

    Given the code you show, eventually your application is likely to leak Connections, leaving the Connection pool exhausted (that is, with all Connections irreversibly checked out). You need to consistently use the robust resource cleanup idiom. See e.g

    http://old.nabble.com/Re:-My-connections-are-all-idle…-p27691635.html

    Once you modify your code to reliably cose Connection, if you still see problems, c3p0 has settings to find and debug unreturned Connections. You can temporarily set an unreturnedConnectionTimeout and using
    debugUnreturnedConnectionStackTraces to track down the leak. See

    http://www.mchange.com/projects/c3p0/index.html#unreturnedConnectionTimeout

    http://www.mchange.com/projects/c3p0/index.html#debugUnreturnedConnectionStackTraces

    But first, just fix your resource cleanup code, and see if the problem goes away. Capturing debugUnreturnedConnectionStackTraces is a performance drag; as the name suggests, it should be used only temporarily, to debug.

    I hope this helps!

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

Sidebar

Related Questions

I have this problem: I want to generate a new source code file from
I have this problem with a lot of arrays in my program, and I
I have this problem.. I'm receiving data from a client..Using a socket connection. But
I have this problem. Session does not work when I use with $_POST. If
I have this problem bothering me for days. I'm making a special paint program.
I have this problem where I need to design a Java package which is
I have this problem. I have a module (module 1) that use Nhibernate to
I have this problem with UISearchDisplayController . I want to use it in a
I have this problem that when I use array as such Array ( [11]
I have this problem in a program which changes panels in a JFrame. I

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.