我已经配置了数据源并将自动提交设置为 false。
<bean id="dbDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${widget.database.driver}" />
<property name="url" value="${widget.database.url}" />
<property name="defaultAutoCommit" value="false" />
<property name="accessToUnderlyingConnectionAllowed" value="true" />
<property name="username" value="${widget.database.username}" />
<property name="password" value="${widget.database.password}" />
<property name="maxActive" value="${widget.database.maxActive}" />
<property name="maxIdle" value="${widget.database.maxIdle}" />
</bean>
在我的 DAO 课程中,我已经做到了。
public void insertDIMFactToDB(WidgetJobOutput jobOutput) throws DataAccessException {
int rowsInserted=0;
try {
logger.info("Databse insert for DIMCODE " + jobOutput.getDimCode() + " having DIMFACT value as : " + + jobOutput.getDimFact());
jdbcTemplate = new JdbcTemplate(dataSource);
Object[] params = new Object[] {
jobOutput.getDimCode(),
jobOutput.getDimFact()
};
rowsInserted = jdbcTemplate.update(DBConstants.INS_WIDGET_HRLY_DATA,
params);
//logger.info("Successfully inserted/updated " + rowsInserted + " in DB");
} catch (DataAccessException e) {
throw e ;
}
// commit everything
try {
DataSourceUtils.getConnection(jdbcTemplate.getDataSource()).commit();
logger.info("Successfully inserted/updated " + rowsInserted + " in DB");
} catch (SQLException e) {
logger.error("Error Occured while commiting data into DB:-"+ ExceptionUtils.getFullStackTrace(e));
}
}
但它既没有抛出任何异常,也没有提交数据。请帮我找到错误。在此先感谢