How can I create a DB Transaction with Joget BeanShell Script
Confluence User - 22 Oct, 2016
Dear Expert,
I would like to make a db transaction with the following code.
Connection con = null;
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
try{
if (!con.isClosed()){
con.setAutoCommit(false);
// Some code to select a Record for checking!
// sql = "select * from tables for update";
...
if (checking == true) {
result = true;
} else {
// Some code update another db record here!
...
};
con.commit();
} catch (Exception e) {
LogUtil.error("Application",e, "Error updateing data");
} finally {
if (con !=null) {
con.close();
};
}
However, I get the error of "java.sql.SQLException: Auto-commit can not be set while enrolled in a transaction"
Everyone can point me how to solve this problem.
Many Thanks!
Best Regards
Tony Chu
beanshell;record;locking;jdbc