java - PreparedStatement executeUpdate on an OracleDataSource connection does not auto commit -
call preparedstatement.executeupdate() returns (with count of rows updated). db not reflect update. seeing issue ojdbc7.jar (tried both java 7 , java 8 ses).
final string update_sql = "update myportfolio set stock = ? key = ?"; final string stock = 'so';// pre ipo :) final long key = 12345l; try (connection conn = pds.getconnection(); preparedstatement proc = conn.preparestatement(update_sql)) { //conn.setautocommit(false); --> works conn.setautocommit(true); // default...but making sure proc.setstring(1, stock); proc.setlong(2, key); int rowcount = proc.executeupdate(); //conn.commit(); --> works logger.info("updated {} rows. sql = {}. stock = {}, key = {}, inboundkey = {}", rowcount, update_sql, stock, key); // logs 1 row updated. db still shows stale data (old stock) key 12345l. } catch (sqlexception e) { throw new persistenceexception(e); } // pool data source settings pooldatasource pds = pooldatasourcefactory.getpooldatasource(); pds.setconnectionfactoryclassname("oracle.jdbc.pool.oracledatasource"); pds.setconnectionpoolname(cachename); pds.seturl(dburl); pds.setuser(username); pds.setpassword(password); pds.setminpoolsize(5); pds.setmaxpoolsize(10); pds.setinitialpoolsize(7); pds.setinactiveconnectiontimeout(10);
if using executeupdate() or execute() need connection.commit(). , if dont want execute commit can go :preparestatement() not require commit().
Comments
Post a Comment