To resolve the issue mentioned here .
We are creating and using 2 same JDBC Singleton Connections(Regular, Proxy).
Note: We are not dealing with multi-threading here.
Issue:
// Auto Commit false
// Singelton
Connection connection = getConnection(); //same
// Auto Commit true
// // Singelton
Connection proxyConnection= getConnection(); //same
PreparedStatement ps = null;
try{
connection.setAutoCommit(false);
//Step 1
String sql = getQuery();
ps = proxyConnection.prepareStatement(sql);
ps.executeUpdate();
.
.
//Step 2
// if I don't execute this step everything works fine.
sql = getTransctionQuery();
ps = connection.prepareStatement(sql);
ps.executeUpdate();
.
.
//Step 3
sql = getQuery();
ps = proxyConnection.prepareStatement(sql);
ps.executeUpdate(); // this line never completes (if Step 2 runs)
}catch(){
connection.rollback(); //Doesn’t rollback step 1 and understandably step 2.
}
finally{
connection.close(); //cleanup code
proxyConnection.close();
}
Question:
Thanks
I'm no expert here but I used to have problems with Oracle DB when running a query and then forgetting to commit (or cancel). So I think that the fact that you didn't commit after step 2 locks the database for the next access.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.