//实际方法
//现在是一个嵌套try,并且还是未进行优化的关流
public void saveMessage(String keycde,String xmlStr,String type,String fromStr) throws PublicException{
Connection conn = null;
PreparedStatement state = null;
try {
try {
conn = this.commonDao.getNewConnection();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new PublicException(“保存报文失败:获取不到连接”,e);
}
String sql = “insert into web_interface_msg” +
“(C_ID,C_KEY_CDE,C_MSG,C_REQUEST_TYPE,C_FROM,C_CRT_CDE,T_CRT_TM,C_UPD_CDE,T_UPD_TM)”
+ " values"
+ “(replace(uuid(), ‘-’, ‘’),?,?,?,?,?,now(),?,now())”;
state = conn.prepareStatement(sql);
state.setString(1, keycde);
state.setCharacterStream(2, new StringReader(xmlStr), xmlStr.length());
state.setString(3, type);
state.setString(4, fromStr);
state.setString(5, “posService”);
st
try-with-resource语法糖优化
最新推荐文章于 2023-08-28 10:33:32 发布