/**
* 添加模版数据
* @param objCommonTemplateVO
* @return
* @throws TemplateException
*/
public int insertCommonTemplate(CommonTemplateVO objCommonTemplateVO)
throws TemplateException {
Connection conn = null;
PreparedStatement pstmtInsert = null;
String strInsert = "INSERT INTO PUB_COMMON_TEMPLATE(TEMPLATE_ID,TEMPLATE_NAME,RELATION_PROJECT,RELATION_MODEL,RELATION_OBJECT,TEMPLATE_CONTENT,EXPORT_TYPE,REMARK) VALUES(?,?,?,?,?,EMPTY_CLOB(),?,?)";
try {
// 设置数据库连接
conn = getConnection();
pstmtInsert = conn.prepareStatement(strInsert, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
pstmtInsert.setInt(1, objCommonTemplateVO.getTemplateId());
pstmtInsert.setString(2, objCommonTemplateVO.getTemplateName());
pstmtInsert.setString(3, objCommonTemplateVO.getRelationProject());
pstmtInsert.setString(4, objCommonTemplateVO.getRelationModel());
pstmtInsert.setString(5, objCommonTemplateVO.getRelationObject());
pstmtInsert.setString(6, objCommonTemplateVO.getExportType());
pstmtInsert.setString(7, objCommonTemplateVO.getRemark());
pstmtInsert.executeUpdate();
} catch (Exception ex) {
logger.error("添加模版时出错", ex);
throw new TemplateException("添加模版时出错", ex);
} finally {
this.closeConnection(pstmtInsert, conn);
}
return objCommonTemplateVO.getTemplateId();
}
/**
* 根据模版编号修改模版内容
* @param iTemplateId 模版编号
* @param strTemplateContent 模版内容
* @throws TemplateException
*/
public int updateTemplateContent(int iTemplateId, String strTemplateContent) throws TemplateException {
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
Writer outStream = null;
String strQuery = "SELECT PC.TEMPLATE_CONTENT FROM PUB_COMMON_TEMPLATE PC WHERE PC.TEMPLATE_ID = ? FOR UPDATE";
try {
// 设置数据库连接
conn = getConnection();
pstmt = conn.prepareStatement(strQuery, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
pstmt.setInt(1, iTemplateId);
rs = pstmt.executeQuery();
rs.next();
OracleThinClob templateContent = (OracleThinClob) rs.getClob("TEMPLATE_CONTENT");
outStream = templateContent.getCharacterOutputStream();
char[] c = strTemplateContent.toCharArray();
outStream.write(c, 0, c.length);
outStream.flush();
outStream.close();
} catch (Exception ex) {
logger.error("插入模版内容时出错", ex);
throw new TemplateException("插入模版内容时出错", ex);
} finally {
this.closeConnection(rs, pstmt, conn);
}
return iTemplateId;
}
chinaunix网友2008-11-05 17:46:54
我靠,我发现我的实现给你的类同,强人,不过我是结合Spring实现的,感觉自己写的东西要少了很多. 我的站点,欢迎来访:http://www.wanjidong.cn