找到2个东西 hibernate http://forum.hibernate.org/viewtopic.php?p=2394664 Spring http://forum.springframework.org/archive/index.php/t-23378.html明天去公司再弄一下才知道~
从上面两个连接,写成这样子过去了。。public class LockDaoEx extends JdbcDaoSupport { private static final Log log = LogFactory.getLog(LockDaoEx.class); private UpdateLock updateLock; protected void initDao() throws Exception { updateLock = new UpdateLock(getDataSource()); } public int batchUpdate(Object[] params) { log.debug("BatchingBatcher#batchUpdate() start."); int ret = 0; try { ret = updateLock.batchUpdate(params); } catch (DataAccessException _ex) { throw _ex; } finally { log.debug("BatchingBatcher#batchUpdate() end."); } return ret; } private static class UpdateLock extends SqlUpdate { private static final String sql = ResourceBean.getResourceStr( MPEConstant.QUERY_PROP_LOCATION, "UPDATE_LOCK"); public UpdateLock(DataSource ds) { super(ds, sql); // SQL実行タイムアウトの設定 this.setJdbcTemplate(new JdbcTemplate(ds) { protected void applyStatementSettings(Statement state) throws SQLException { state.setQueryTimeout(MPEConstant.QUERY_TIMEOUT); } }); declareParameter(new SqlParameter(Types.CHAR)); declareParameter(new SqlParameter(Types.CHAR)); declareParameter(new SqlParameter(Types.CHAR)); compile(); } protected int batchUpdate(Object[] params) throws DataAccessException { if (params != null) { String[] sqlArray = new String[params.length]; for (int i = 0; i < params.length; i++) { sqlArray[i] = MPEDBUtil.getFullSqlString( (Object[]) params[i], sql); } return flush(sqlArray); } return -1; } private int flush(String[] sql) { int[] affected = getJdbcTemplate().batchUpdate(sql); int totalRowsAffected = 0; for (int i = 0; i < affected.length; i++) { totalRowsAffected += affected[i]; } return totalRowsAffected; } } public static void main(String[] args) { LockDaoEx updateLock = (LockDaoEx) SpringWrpCmp.getComponent("updateLock"); Object[] orgs1 = new Object[] { "T_SGYOTEI ", "yinwh ", MPEDBUtil.fillingAfterStr("1", " ", 20) }; Object[] orgs2 = new Object[] { "T_SGYOTEI ", "yinwh ", MPEDBUtil.fillingAfterStr("2", " ", 20) }; Object[] orgs3 = new Object[] { "T_SGYOTEI ", "yinwh ", MPEDBUtil.fillingAfterStr("3", " ", 20) }; System.out.println("" + updateLock.batchUpdate(new Object[] { orgs1, orgs2, orgs3 })); } }
hibernate
http://forum.hibernate.org/viewtopic.php?p=2394664
Spring
http://forum.springframework.org/archive/index.php/t-23378.html明天去公司再弄一下才知道~
updateLock = new UpdateLock(getDataSource());
} public int batchUpdate(Object[] params) {
log.debug("BatchingBatcher#batchUpdate() start.");
int ret = 0;
try {
ret = updateLock.batchUpdate(params);
} catch (DataAccessException _ex) {
throw _ex;
} finally {
log.debug("BatchingBatcher#batchUpdate() end.");
}
return ret;
} private static class UpdateLock extends SqlUpdate { private static final String sql = ResourceBean.getResourceStr(
MPEConstant.QUERY_PROP_LOCATION, "UPDATE_LOCK"); public UpdateLock(DataSource ds) {
super(ds, sql);
// SQL実行タイムアウトの設定
this.setJdbcTemplate(new JdbcTemplate(ds) {
protected void applyStatementSettings(Statement state)
throws SQLException {
state.setQueryTimeout(MPEConstant.QUERY_TIMEOUT);
}
});
declareParameter(new SqlParameter(Types.CHAR));
declareParameter(new SqlParameter(Types.CHAR));
declareParameter(new SqlParameter(Types.CHAR));
compile();
} protected int batchUpdate(Object[] params) throws DataAccessException {
if (params != null) {
String[] sqlArray = new String[params.length];
for (int i = 0; i < params.length; i++) {
sqlArray[i] = MPEDBUtil.getFullSqlString(
(Object[]) params[i], sql);
}
return flush(sqlArray);
}
return -1;
} private int flush(String[] sql) {
int[] affected = getJdbcTemplate().batchUpdate(sql);
int totalRowsAffected = 0;
for (int i = 0; i < affected.length; i++) {
totalRowsAffected += affected[i];
}
return totalRowsAffected;
}
} public static void main(String[] args) {
LockDaoEx updateLock = (LockDaoEx) SpringWrpCmp.getComponent("updateLock");
Object[] orgs1 = new Object[] { "T_SGYOTEI ", "yinwh ",
MPEDBUtil.fillingAfterStr("1", " ", 20) };
Object[] orgs2 = new Object[] { "T_SGYOTEI ", "yinwh ",
MPEDBUtil.fillingAfterStr("2", " ", 20) };
Object[] orgs3 = new Object[] { "T_SGYOTEI ", "yinwh ",
MPEDBUtil.fillingAfterStr("3", " ", 20) };
System.out.println(""
+ updateLock.batchUpdate(new Object[] { orgs1, orgs2, orgs3 }));
}
}