Skip to Content
avatar image
Former Member

Java Database Connections couldn't be closed on PI 7.1 EHP1

Hi, I develop a dynamic web project to PI. And I use Database conection in that web project. Even I closed the connection in java , Connection doesn't closed and after a while PI pooling size reach the maximum size and PI doesn't response. I find open connections on MSSQL and connections' status are sleeping, cmd fields are AWAITING COMMAND. I have to restart PI these to close that connections.

I get Connections like these code

...

InitialContext cxt = new InitialContext();

final DataSourceManager dsm = (DataSourceManager) cxt

.lookup("dbpool");

String lookUpName = dsm.getSystemDataSourceDescriptor().getDataSourceName();

DataSource ds = (DataSource) cxt.lookup("jdbc/" + lookUpName);

ds.setLoginTimeout(60);

conn = ds.getConnection();...

and I close connections like these

...

conn = db.getDefaultDatabaseConnection();

if (conn != null) {

try {

conn.setAutoCommit(true);

String sql = "INSERT INTO

....

pstmt.close();

conn.close();

} catch (Exception e) {

.....

} finally {

try {

pstmt.close();

conn.close();

} catch (SQLException e2) {

e.printStackTrace();

}

e.printStackTrace();

}

I changed system DataSource's and i give these parameters

Initial Connections: 5

Maximum Connections: 125

Maximum Time to Wait for Connection: 90

Connection Lifetime (Sec.): 60

Cleanup Interval (Sec.) : 90

it didn't work either

Can anyone hepl me ?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 22, 2011 at 12:26 AM

    I would like to make slight changes in code. . Please close the resources only in finally block.

    Dont know you are closing resultset or not. If not, you must close it

    conn = db.getDefaultDatabaseConnection();

    try {

    if (conn != null) {

    conn.setAutoCommit(true);

    String sql = "INSERT INTO

    ....

    }

    } catch (Exception e) {

    .....

    } finally {

    try{

    if(rs != null){

    rs.close()

    }

    }catch(SqlException se){

    //log it

    }

    try{

    if(stmt != null){

    stmt.close();

    }

    }catch(SqlException se){

    //log it

    }

    try{

    if(conn != null){

    conn.close();

    }

    } catch(SQLException ss){

    // log it

    }

    } // end of finally

    Hope this help.

    Add comment
    10|10000 characters needed characters exceeded