在我的数据库访问对象中,我有一个由 servlet 执行的 void 方法:
我的道:
public void saveGL(glmaintenancebean glm) {
username = glm.getUsername();
date = glm.getDate();
code = glm.getCode();
branch = glm.getBranch();
currency = glm.getCurrency();
description = glm.getDescription();
type = glm.getType();
String bankid = getBankId();
Connection conn;
try{
conn = db.getDbConnection();
String sql = "insert into gl_master (GL_CODE,GL_BRANCH,GL_CURRENCY,GL_DESC,GL_TYPE,BANK_ID,"
+ "RCRE_USER,RCRE_DATE,LMOD_USER,LMOD_DATE) VALUES(?,?,?,?,?,?,?,"
+ "to_date(?,'yyyy/mm/dd hh24:mi:ss'),?,to_date(?,'yyyy/mm/dd hh24:mi:ss'))";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, code.toUpperCase());
ps.setString(2, branch.toUpperCase());
ps.setString(3, currency.toUpperCase());
ps.setString(4, description.toUpperCase());
ps.setString(5, type.toUpperCase());
ps.setString(6, bankid.toUpperCase());
ps.setString(7, username.toUpperCase());
ps.setString(8, date);
ps.setString(9, username.toUpperCase());
ps.setString(10, date);
ps.executeUpdate();
}catch(Exception asd){
System.out.println(asd.getMessage());
}
}
我的小服务程序;
glmaintenancedao gld = new glmaintenancedao();//My Dao
if (gld.glAlreadyExists(glm) == false) {
if (gld.usersolandenteredsolMismatch(glm) == false) {
gld.saveGL(glm);//My void method called
request.setAttribute("succ", "General Ledger added Succesfully");
request.getRequestDispatcher("/WEB-INF/gl/glmaintenanance_succ.jsp").forward(request, response);
} else {
request.setAttribute("succ", "User not Authorised to add Gl In another Branch!!");
request.getRequestDispatcher("/WEB-INF/gl/glmaintenanance_succ.jsp").forward(request, response);
}
我需要向用户报告任何由 void dao 方法引起的错误,比如所有 ORA 错误都说无效的列名、表或视图不存在。
在我的代码中,如果遇到数据库或错误,系统仍然会显示已成功添加的总帐:
艾米的想法将被欣赏。