Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.sql2o.Sql2oException: Error in executeUpdate, ORA-01000: maximum open cursors exceeded #312

Open
zakjar opened this issue Dec 31, 2018 · 0 comments

Comments

@zakjar
Copy link

zakjar commented Dec 31, 2018

I use ConnectionPool - org.apache.tomcat.jdbc.pool.DataSource
My database is Oracle with 300 limit open cursor
And this code finish with ORA-01000 Exception

for ( int i = 0; i < 400; i++ )
try(Connection con = AbsObject.getOpenedConnection() ) {
con.createQuery("insert into xxx ( id ) values ( 1 )" ).executeUpdate();
con.commit();
}

this code is correct : when I use con.commit(false)

for ( int i = 0; i < 400; i++ )
try(Connection con = AbsObject.getOpenedConnection() ) {
con.createQuery("insert into xxx ( id ) values ( 1 )" ).executeUpdate();
con.commit(false);
}

I see in source code problem in Connection.close()
Code getSql2o().getQuirks().closeStatement(statement) is never call if I use commit(true), because connectionIsClosed is true

    if (!connectionIsClosed) {
        for (Statement statement : statements) {
            try {
                getSql2o().getQuirks().closeStatement(statement);
            } catch (Throwable e) {
                logger.warn("Could not close statement.", e);
            }
        }
        statements.clear();

I think that Connection.commit( boolean) for connection pool have to close preparedStatement.
And Connection.commit needs to be changed like this :

public Connection commit(boolean closeConnection){
    try {
        jdbcConnection.commit();
    }
    catch (SQLException e) {
        throw new Sql2oException(e);
    }
    finally {
        if(closeConnection) {
            //  ------------  close all prepared statement -----------  new code -----------
            for (Statement statement : statements) {
                try {
                    getSql2o().getQuirks().closeStatement(statement);
                } catch (Throwable e) {
                    logger.warn("Could not close statement.", e);
                }
            }
            statements.clear();
            //  --------------------------------------------------------------   end new code -------
            this.closeJdbcConnection();
      }
    }
    return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant