Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Please ask technical questions in the appropriate category. Thank you!

Autocommit issue with JDK 1.8, Tomcat 9.0.60, ojdbc8.jar and Oracle DB 19c (19.14.0.0.)

User_3BPQAFeb 15 2023

Hello everyone,

Recently we have done an environment setup upgradation/migration as mentioned below for our application:
JDK 1.7 ---> JDK 1.8
Tomcat 7.0.47 ---> Tomcat 9.0.60 (Also using Apache HTTP Server along with Apache Tomcat for new setup)
ojdbc7.jar ---> ojdbc8.jar
Oracle 12c (12.1.0.2.0) ---> Oracle 19c (19.14.0.0)

We have been facing a JDBC autocommit issue since then in this new environment setup:

Issue: For the first time AutoCommit is true by default. We update the value of autocommit to false and manually commit the transaction. After that, we also close the connection. Now if we try to create another connection object with "DataSource.getConnection()" within 10 seconds (in debug mode), the previous connection object is getting assigned with autocommit value to false. But, we expect a new connection object to be assigned with autocommit value set to true.

During debugging, we found that in the "GenericObjectPool" class, inside the method "borrowObject", the line "p = idleObjects.pollFirst();" assigns
(i) if within 10 seconds=> the value of p is the previous connection object; or,
(ii) if after 10 seconds=> the value of p is null and thus one new connection object is created for p with autocommit value to true

public T borrowObject(final Duration borrowMaxWaitDuration) throws Exception {
...........
...........
...........
while (p == null) {
create = false;
p = idleObjects.pollFirst();
if (p == null) {
p = create();
if (p != null) {
create = true;
}
}
}
.........
.........
.........
}

Our initial understanding is that this code segment is the reason behind such behavior. But, please help us understand the reason why it is behaving differently in the new environment setup. Also, please help us with the Java source code to create a new connection object with autocommit value to true for subsequent connection objects.

***Note: In the previous old environment setup mentioned before, the same source code works perfectly fine i.e. the autocommit is set to true by default every time we try to create a connection object with the same code "DataSource.getConnection()".

Thanks in Advance.

Comments
Post Details
Added on Feb 15 2023
3 comments
1,246 views