DBResultSetSender proxy = DBResultSetSender.newSender(lineSender);
proxy.setMonitor(getMonitor());
proxy.setDateFormatMap(genDateFormatMap());
if(sql.isEmpty()){
logger.error("Sql for SqlserverReader is empty.");
throw new WormholeException("Sql for SqlserverReader is empty.",JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD);
}
logger.debug(String.format("SqlserverReader start to query %s .", sql));
for(String sqlItem:sql.split(";")){
sqlItem = sqlItem.trim();
if(sqlItem.isEmpty()) {
continue;
}
logger.debug(sqlItem);
ResultSet rs = null;
try {
rs = DBUtils.query(conn, sqlItem);
proxy.sendToWriter(rs);
proxy.flush();
} catch (SQLException e) {
logger.error(e.getMessage());
throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD);
} catch (WormholeException e1) {
e1.setStatusCode(e1.getStatusCode() + ERROR_CODE_ADD);
throw e1;
} finally {
if (null != rs) {
try {
DBUtils.closeResultSet(rs);
} catch (SQLException e) {
logger.error("SqlserverReader close resultset error ");
throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD);
}
}
}
}
}