My first suggestion would be to upgrade the update Spring Library including Spring JDBC and JPA version to latest. The earlier spring JPA version was not closing the cursors properly.
This problem occurs commonly because of not cleaning up resultsets
, statements or connections. Each ResultSet that you create, uses a cursor on the backend. If you never close the ResultSet, the Statement that created it or the Connection that was used for the statement, those cursors never get closed. As you are using a connection pool, the connections are never physically closed, thus the cursors are never closed either.
What causes the Solve ora-01000 maximum open cursors exceeded java.sql.SQLException
problem in JDBC java-
- Not closing the JDBC
Statement
object can cause maximum open cursors
exceeded java.sql.SQLException,
- Not closing the JDBC
PreparedStatement
object can cause maximum open
cursors exceeded java.sql.SQLException,
- Not closing the JDBC
CallableStatement
object can cause maximum open
cursors exceeded java.sql.SQLException,
- Not closing the JDBC
ResultSet
object and Not closing the JDBC
Connections object can cause maximum open cursors exceeded
java.sql.SQLException
Does Spring JdbcTemplate Close Connections? … Not Always.
Decent developers usually know that they have to try/catch/finally to ensure they clean up connections, file handles, or any number of things. But then, for Java, you hear “just use JdbcTemplate
! it does all this boilerplate for you!”. I had, for the longest time, assumed that JdbcTemplate
would clean up connections in addition to results sets. In fact, you’ll see this online a lot. But be careful! This does not appear to be the case, or if it is, it is at least data source dependent… and that actually makes sense if you think about their purpose.
When you don't have a Spring managed transaction then yes the JdbcTemplate
will call the close()
method on the Connection. However if there was already a connection available due to Springs transaction management closing the connection will be handled by Springs transaction support, which in turn also will call close()
on the Connection.
EDIT:
Workaround:
Increase the maximum open cursor in the database by executing the following SQL command on the database:
ALTER SYSTEM SET open_cursors = 1000 SCOPE=BOTH;
This example sets the maximum open cursors to 1000. Change this value as required.
Resolution:
Update the Oracle JDBC Driver to the latest version (12.2.0.1)
There is a new version of the Oracle JDBC driver which fixes the cursor leak.