Search in sources :

Example 1 with DelStaffResponse

use of beans.response.DelStaffResponse in project MSEC by Tencent.

the class DelStaff method exec.

public DelStaffResponse exec(DelStaffRequest request) {
    DelStaffResponse response = new DelStaffResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getStaff_name() == null || request.getStaff_name().equals("")) {
        response.setMessage("The name of staff to be deleted should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    String sql = "delete from t_staff where staff_name=?";
    List<Object> params = new ArrayList<Object>();
    params.add(request.getStaff_name());
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        if (delNum >= 0) {
            response.setMessage("success");
            response.setDeleteNumber(delNum);
            response.setStatus(0);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("Delete record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
    return response;
}
Also used : DBUtil(msec.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DelStaffResponse(beans.response.DelStaffResponse)

Aggregations

DelStaffResponse (beans.response.DelStaffResponse)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DBUtil (msec.org.DBUtil)1