* @return 影响行数
* @throws DAOException
*/
public Integer update(String tableName, Map<String, Object> data, String sql, Object[] sdata) throws FixFlowException {
if (data.size() < 1) {
throw new FixFlowException("插入错误: 无效的数据输入");
}
/* 构造插入查询语句 */
StringBuffer querySql = new StringBuffer("UPDATE ");
querySql.append(tableName);
querySql.append(" SET ");
Set<String> keys = data.keySet();
for (Object key : keys.toArray()) {
querySql.append((String) key);
querySql.append(" = ? , ");
}
querySql = new StringBuffer(querySql.substring(0, querySql.lastIndexOf(",")));
if (null != sql) {
querySql.append(" WHERE ");
querySql.append(sql);
}
/* 构造插入查询语句 */
PreparedStatement pstmt=null;
Integer affectRow = 0;
try {
debugLog.debug("FixFlow引擎数据持久化语句: " +querySql.toString());
debugLog.debug("参数data: "+ data);
debugLog.debug("参数sdata: "+ Arrays.asList(sdata));
pstmt = conn.prepareStatement(querySql.toString());
Object[] keyArray = keys.toArray();
int j = 1;
for (int i = 0; i < keyArray.length; i++) {
Object returnObj = transformSqlType(data.get((String) keyArray[i]));
if (returnObj == null) {
pstmt.setNull(j++, Types.VARCHAR);
} else {
pstmt.setObject(j++, returnObj);
}
}
if (null != sdata && sdata.length > 0) {
for (int i = 0; i < sdata.length; i++) {
Object returnObj = transformSqlType(sdata[i]);
if (returnObj == null) {
pstmt.setNull(j++, Types.VARCHAR);
} else {
pstmt.setObject(j++, returnObj);
}
}
}
affectRow = pstmt.executeUpdate();
} catch (SQLException e) {
throw new FixFlowException("查询错误:" + e.getMessage(), e);
}
finally
{
try {
pstmt.close();
} catch (SQLException e) {
throw new FixFlowException("关闭游标失败",e);
}
}
return affectRow;
}