How to manage db connections on server?
        Posted  
        
            by simpatico
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by simpatico
        
        
        
        Published on 2010-06-05T06:26:30Z
        Indexed on 
            2010/06/05
            6:32 UTC
        
        
        Read the original article
        Hit count: 308
        
I have a severe problem with my database connection in my web application. Since I use a single database connection for the whole application from singleton Database class, if i try concurrent db operations (two users) the database rollsback the transactions. This is my static method used:
All threads/servlets call static Database.doSomething(...) methods, which in turn call the the below method.
private static /* synchronized*/ Connection getConnection(final boolean autoCommit) throws SQLException {
    if (con == null) {
        con = new MyRegistrationBean().getConnection();
    }
    con.setAutoCommit(true); //TODO
    return con;
}
What's the recommended way to manage this db connection/s I have, so that I don't incurr in the same problem.
© Stack Overflow or respective owner