⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logdao.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    int rowCount = 0;    try {      dbConnection = getDBConnection();      stmt = dbConnection.createStatement();      rs = stmt.executeQuery(sql);      if ( rs.next() ) {        rowCount = rs.getInt(1);      }else{        Debug.println(sql + "\n" + "ERROR in get row count!!");        throw new SysException("ERROR in get row count!!");      }      return rowCount;    } catch(SQLException e) {      Debug.println(sql + "\n" + "SQLException while execute getRowCountBySql mothod :\n" + e);      throw new SysException("SQLException while execute getRowCountBySql mothod :\n" + e);    } finally {      closeResultSet(rs);      closeStatement(stmt);      closeConnection(dbConnection);    }  }  public static Collection queryAll() throws SysException {    String sql = "SELECT ROWID, ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE FROM SXIT_WAP_LOG";    return queryBySql(sql);  }  public static Collection queryAll(int beginRow, int endRow) throws SysException {    String sql = "SELECT ROWID, ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE FROM SXIT_WAP_LOG";    return queryBySql(sql, beginRow, endRow);  }  public static int getRowCountOfAll() throws SysException {    String sql = "SELECT COUNT(*) FROM SXIT_WAP_LOG";    return getRowCountBySql(sql);  }  public static LogModel toModel(Hashtable element) {    LogModel model = new LogModel();    model.setAdminName((String)element.get("adminName"));    model.setLogContent((String)element.get("logContent"));    model.setLogDate((Timestamp)element.get("logDate"));    model.setLogLevel((String)element.get("logLevel"));    model.setLogType((String)element.get("logType"));    return model;  }  public static Collection allToModel(Collection coll) {    Collection value = new ArrayList();    Iterator it = coll.iterator();    while (it.hasNext()) {      value.add(toModel((Hashtable)it.next()));    }    return value;  }  public static int getSequenceNextValue() throws SysException {    String sql = "SELECT * FROM SXIT_WAP_SEQUENCE WHERE TABLE_NAME = 'SXIT_WAP_LOG'";    Connection dbConnection = null;    Statement stmt = null;    ResultSet rs = null;    int lastValue = 1;    try {      dbConnection = getDBConnection();      stmt = dbConnection.createStatement();      rs = stmt.executeQuery(sql);      if ( rs.next() ) {        lastValue = rs.getInt("LAST_VALUE");        int minValue = rs.getInt("MIN_VALUE");        int maxValue = rs.getInt("MAX_VALUE");        int incrementBy = rs.getInt("INCREMENT_BY");        int cycle = rs.getInt("CYCLE");        if (lastValue < 0) {          Debug.println("id last value can't smaller than 0");          throw new SysException("id last value can't smaller than 0");        }        if (minValue < 0) {          Debug.println("id min value can't smaller than 0");          throw new SysException("id min value can't smaller than 0");        }        if (maxValue < 0) {          Debug.println("id max value can't smaller than 0");          throw new SysException("id max value can't smaller than 0");        }        if (incrementBy < 1) {          Debug.println("id increment value can't smaller than 1");          throw new SysException("id increment value can't smaller than 1");        }        if (cycle != 0 && cycle != 1) {          Debug.println("id cycle value error, it can be 0 or 1 only");          throw new SysException("id cycle value error, it can be 0 or 1 only");        }        if (lastValue < minValue) {          Debug.println("id value is " + lastValue + ": \n" + "id value can't smaller than min value");          throw new SysException("id value can't smaller than min value");        }        if (minValue >= maxValue) {          Debug.println("id max value must bigger than min value");          throw new SysException("id max value must bigger than min value");        }        if (lastValue > maxValue) {          if (cycle == 0) {            Debug.println("id value is " + lastValue + ": \n" + "id value exceeds max value");            throw new SysException("id value exceeds max value");          } else {            lastValue = minValue;          }        }        sql = "UPDATE SXIT_WAP_SEQUENCE SET LAST_VALUE = " + (lastValue + incrementBy) + " WHERE TABLE_NAME = 'SXIT_WAP_LOG'";        stmt.executeUpdate(sql);      }else{        sql = "INSERT INTO SXIT_WAP_SEQUENCE (TABLE_NAME, LAST_VALUE, MIN_VALUE, MAX_VALUE, INCREMENT_BY, CYCLE) VALUES ('SXIT_WAP_LOG', 2, 1, 999999999, 1, 1)";        stmt.executeUpdate(sql);      }      return lastValue;    } catch(SQLException e) {      Debug.println(sql + "\n" + "SQLException while execute getRowCountBySql method :\n" + e);      throw new SysException("SQLException while execute getRowCountBySql method :\n" + e);    } finally {      closeResultSet(rs);      closeStatement(stmt);      closeConnection(dbConnection);    }  }  protected static String getInsertSQL(LogModel model) {    String sql = "";    if (Database.dbType == DBType.ORACLE) {      sql = "INSERT INTO SXIT_WAP_LOG (ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE) VALUES ('"          + Function.writeDBEncode(model.getAdminName()) + "', '"          + Function.writeDBEncode(model.getLogContent()) + "', TO_DATE('"          + Function.DateToString(model.getLogDate()) + "', 'YYYY/MM/DD HH24:MI:SS'), '"          + Function.writeDBEncode(model.getLogLevel()) + "', '"          + Function.writeDBEncode(model.getLogType()) + "')";    } else if (Database.dbType == DBType.SQLSERVER) {      sql = "INSERT INTO SXIT_WAP_LOG (ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE) VALUES ('"          + Function.writeDBEncode(model.getAdminName()) + "', '"          + Function.writeDBEncode(model.getLogContent()) + "', '"          + Function.DateToString(model.getLogDate()) + "', '"          + Function.writeDBEncode(model.getLogLevel()) + "', '"          + Function.writeDBEncode(model.getLogType()) + "')";    } else if (Database.dbType == DBType.MYSQL) {      sql = "INSERT INTO SXIT_WAP_LOG (ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE) VALUES ('"          + Function.writeDBEncode(model.getAdminName()) + "', '"          + Function.writeDBEncode(model.getLogContent()) + "', '"          + Function.DateToString(model.getLogDate()) + "', '"          + Function.writeDBEncode(model.getLogLevel()) + "', '"          + Function.writeDBEncode(model.getLogType()) + "')";    }    return sql;  }  protected static String getUpdateSQL(String rowid, LogModel model) {    String sql = "UPDATE SXIT_WAP_LOG SET ADMIN_NAME = '"          + Function.writeDBEncode(model.getAdminName()) + "', LOG_CONTENT = '"          + Function.writeDBEncode(model.getLogContent()) + "', LOG_DATE = TO_DATE('"          + Function.DateToString(model.getLogDate()) + "', 'YYYY-MM-DD HH24:MI:SS'), LOG_LEVEL = '"          + Function.writeDBEncode(model.getLogLevel()) + "', LOG_TYPE = '"          + Function.writeDBEncode(model.getLogType()) + "'"          + " WHERE ROWID = '" + rowid + "'";    return sql;  }  protected static String getDeleteSQL(String rowid) {    String sql = "DELETE FROM SXIT_WAP_LOG"          + " WHERE ROWID = '" + rowid + "'";    return sql;  }  protected static String getDeleteSQL(String[] rowids) {    String sql = "DELETE FROM SXIT_WAP_LOG WHERE 1 = 2";      for ( int i = 0; i < rowids.length; i++ ) {        sql += " OR (ROWID = '" + rowids[i] + "')";      }    return sql;  }  protected static String getFindByPKSQL(String rowid) {    String sql = "SELECT * FROM SXIT_WAP_LOG"          + " WHERE ROWID = '" + rowid + "'";    return sql;  }  protected static boolean isValidData(LogModel model) {    return true;  }  private static Connection getDBConnection() throws SysException {    return Database.getConnection();  }  private static void closeConnection(Connection dbConnection) throws SysException {    try {      if (dbConnection != null && !dbConnection.isClosed()) {        dbConnection.close();        dbConnection = null;      }    } catch (SQLException se) {      //throw new SysException("SQL Exception while closing DB connection : \n" + se);    }  }  private static void closeResultSet(ResultSet result) throws SysException {    try {      if (result != null) {        result.close();      }    } catch (SQLException se) {      //throw new SysException("SQL Exception while closing Result Set : \n" + se);    }  }  private static void closeStatement(Statement stmt) throws SysException {    try {      if (stmt != null) {        stmt.close();      }    } catch (SQLException se) {      //throw new SysException("SQL Exception while closing Statement : \n" + se);    }  }  public static void main(String[] args) throws Exception{    String action = "";    if (args.length == 1) {      action = args[0];    }    if (action == null || "".equals(action)) {    } else if ("insert".equalsIgnoreCase(action)) {      LogModel model=new LogModel();      model.setAdminName("abc");      model.setLogContent("abc");      model.setLogDate(Function.getCurrTime());      model.setLogLevel("abc");      model.setLogType("abc");      LogModel logModel = LogBean.insert(model);    }else if ("update".equalsIgnoreCase(action)){      LogModel logModel = LogBean.findByPK("AAADZ1AAHAAAd4KAAA");      String adminName = logModel.getAdminName();      String logContent = logModel.getLogContent();      Timestamp logDate = logModel.getLogDate();      String logLevel = logModel.getLogLevel();      String logType = logModel.getLogType();      logModel.setAdminName(adminName);      logModel.setLogContent(logContent);      logModel.setLogDate(logDate);      logModel.setLogLevel(logLevel);      logModel.setLogType(logType);      update("AAADZ1AAHAAAd4KAAA", logModel);    }else if ("delete".equalsIgnoreCase(action)){      String[] rowids = new String[3];      rowids[0] = "AAADZ1AAHAAAd4KAAA";      rowids[1] = "AAADZ1AAHAAAd4KAAB";      rowids[2] = "AAADZ1AAHAAAd4KAAC";      LogBean.delete(rowids);    }else if ("findByPK".equalsIgnoreCase(action)){      LogModel logModel = LogBean.findByPK("AAADZ1AAHAAAd4KAAA");      String adminName = logModel.getAdminName();      String logContent = logModel.getLogContent();      Timestamp logDate = logModel.getLogDate();      String logLevel = logModel.getLogLevel();      String logType = logModel.getLogType();      System.out.println("adminName = " + adminName);      System.out.println("logContent = " + logContent);      System.out.println("logDate = " + Function.getYYYYMMDDHHMISS(logDate));      System.out.println("logLevel = " + logLevel);      System.out.println("logType = " + logType);    }else if ("queryBySql".equalsIgnoreCase(action)){      Collection coll = LogBean.queryBySql("SELECT ROWID, ADMIN_NAME, LOG_CONTENT, LOG_DATE, LOG_LEVEL, LOG_TYPE FROM SXIT_WAP_LOG");    }else if ("getRowCountBySql".equalsIgnoreCase(action)){      int rowCount = LogBean.getRowCountBySql("SELECT COUNT(*) FROM SXIT_WAP_LOG");      System.out.println("rowCount = " + rowCount);    }else if ("queryAll".equalsIgnoreCase(action)){      Collection coll = LogBean.queryAll();      Iterator it = coll.iterator();      while ( it.hasNext() ) {        Hashtable element = (Hashtable)it.next();        String rowid = (String)element.get("rowid");        String adminName = (String)element.get("adminName");        String logContent = (String)element.get("logContent");        String logDate = Function.getYYYYMMDDHHMISS((Timestamp)element.get("logDate"));        String logLevel = (String)element.get("logLevel");        String logType = (String)element.get("logType");        System.out.print("rowid = " + rowid + ",\t");        System.out.print("adminName = " + adminName + ",\t");        System.out.print("logContent = " + logContent + ",\t");        System.out.print("logDate = " + logDate + ",\t");        System.out.print("logLevel = " + logLevel + ",\t");        System.out.print("logType = " + logType + "\n");      }    }else if ("getRowCountOfAll".equalsIgnoreCase(action)){      int rowCount = LogBean.getRowCountOfAll();      System.out.println("rowCount = " + rowCount);    }else if ("getSequenceNextValue".equalsIgnoreCase(action)){      int sequenceValue = LogBean.getSequenceNextValue();      System.out.println("sequenceValue = " + sequenceValue);    }  }}/*String adminName = (model==null?"":model.getAdminName());String logContent = (model==null?"":model.getLogContent());Timestamp logDate = (model==null?null:model.getLogDate());String logLevel = (model==null?"":model.getLogLevel());String logType = (model==null?"":model.getLogType());String adminName = PageUtil.parseStringField(request.getParameter("adminName"), "adminName", false, 19);String logContent = PageUtil.parseStringField(request.getParameter("logContent"), "logContent", false, 199);String logLevel = PageUtil.parseStringField(request.getParameter("logLevel"), "logLevel", false, 3);String logType = PageUtil.parseStringField(request.getParameter("logType"), "logType", false, 3);String adminName = PageUtil.parseStringField(request.getParameter("adminName"), "adminName", false, 20);String logContent = PageUtil.parseStringField(request.getParameter("logContent"), "logContent", true, 200);Timestamp logDate = PageUtil.parseDateField(request.getParameter("logDate"), "logDate", true);String logLevel = PageUtil.parseStringField(request.getParameter("logLevel"), "logLevel", true, 4);String logType = PageUtil.parseStringField(request.getParameter("logType"), "logType", true, 4);String adminName = (model==null?"":""+model.getAdminName());String logContent = (model==null?"":""+model.getLogContent());Timestamp logDate = (model==null?null:model.getLogDate());String logLevel = (model==null?"":""+model.getLogLevel());String logType = (model==null?"":""+model.getLogType());Collection coll = LogBean.queryAll((pageNum-1) * pageRow + 1, pageNum * pageRow);Iterator it = coll.iterator();while ( it.hasNext() ) {    Hashtable element = (Hashtable)it.next();    LogModel logModel = LogBean.toModel(element);    String adminName = logModel.getAdminName();    String logContent = logModel.getLogContent();    Timestamp logDate = logModel.getLogDate();    String logLevel = logModel.getLogLevel();    String logType = logModel.getLogType();        excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), adminName+"");        excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), logContent+"");        excel.setCellData(new ExcelCell(ExcelUtil.DATE_CELL_TYTE,   currRow, currCol++), logDate);        excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), logLevel+"");        excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), logType+"");*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -