📄 modifylogdao.java
字号:
package com.sxit.wap.modifylog;import java.sql.*;import java.util.*;import com.sxit.wap.common.*;import com.sxit.wap.exception.*;public class ModifyLogDao { public static String tableName = "WAP_MODIFY_LOG"; public static ModifyLogModel insert(ModifyLogModel model) throws SysException,UpdateException,AppException { if (!ModifyLogBean.isValidData(model)) { Debug.println(model.toString() + "\n" + "Illegal data values for insert"); throw new AppException("Illegal data values for insert"); } String sql = getInsertSQL(model); Connection dbConnection = null; Statement stmt = null; try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != 1 ) { Debug.println(sql + "\n" + "ERROR in INSERT !! resultCount = " + resultCount); throw new UpdateException("ERROR in INSERT !! resultCount = " + resultCount); } return model; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute insert method :\n" + e); throw new SysException("SQLException while execute insert method :\n" + e); } finally { closeStatement(stmt); closeConnection(dbConnection); } } public static ModifyLogModel insert(ModifyLogModel model, Connection dbConnection) throws SysException,UpdateException,AppException { if (!ModifyLogBean.isValidData(model)) { Debug.println(model.toString() + "\n" + "Illegal data values for insert"); throw new AppException("Illegal data values for insert"); } String sql = getInsertSQL(model); Statement stmt = null; try { stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != 1 ) { Debug.println(sql + "\n" + "ERROR in INSERT !! resultCount = " + resultCount); throw new UpdateException("ERROR in INSERT !! resultCount = " + resultCount); } return model; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute insert method :\n" + e); throw new SysException("SQLException while execute insert method :\n" + e); } finally { closeStatement(stmt); } } public static int updateBySql(String sql) throws SysException { Connection dbConnection = null; Statement stmt = null; try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); return stmt.executeUpdate(sql); } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute updateBySql mothod :\n" + e); throw new SysException("SQLException while execute updateBySql mothod :\n" + e); } finally { closeStatement(stmt); closeConnection(dbConnection); } } public static int updateBySql(String sql, Connection dbConnection) throws SysException { Statement stmt = null; try { stmt = dbConnection.createStatement(); return stmt.executeUpdate(sql); } catch(SQLException e) { Debug.println(sql + "\nSQLException while execute updateBySql mothod :\n" + e); throw new SysException("SQLException while execute updateBySql mothod :\n" + e); } finally { closeStatement(stmt); } } public static Collection queryBySql(String sql) throws SysException { Connection dbConnection = null; Statement stmt = null; ResultSet rs = null; ArrayList list = new ArrayList(); try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while ( rs.next() ) { Hashtable element = new Hashtable(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String columnName = rsmd.getColumnName(i); String fieldName = Function.format(columnName); String fieldType = ColumnType.getFieldType(Database.dbType, rsmd, i); if (fieldType == null) continue; if ("Timestamp".equals(fieldType)) { element.put(fieldName, rs.getTimestamp(columnName)); } else if ("String".equals(fieldType)) { String value = Function.readDBEncode(rs.getString(columnName)); if (value == null) value = ""; element.put(fieldName, value); } else if ("int".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getInt(columnName))); } else if ("long".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getLong(columnName))); } else if ("float".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getFloat(columnName))); } } list.add(element); } return list; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute queryBySql mothod :\n" + e); throw new SysException("SQLException while execute queryBySql mothod :\n" + e); } finally { closeResultSet(rs); closeStatement(stmt); closeConnection(dbConnection); } } public static Collection queryBySql(String sql, int beginRow, int endRow) throws SysException { Connection dbConnection = null; Statement stmt = null; ResultSet rs = null; ArrayList list = new ArrayList(); try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); int row = 0; while ( rs.next() ) { if (++row < beginRow) continue; if (row > endRow) break; Hashtable element = new Hashtable(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String columnName = rsmd.getColumnName(i); String fieldName = Function.format(columnName); String fieldType = ColumnType.getFieldType(Database.dbType, rsmd, i); if (fieldType == null) continue; if ("Timestamp".equals(fieldType)) { element.put(fieldName, rs.getTimestamp(columnName)); } else if ("String".equals(fieldType)) { String value = Function.readDBEncode(rs.getString(columnName)); if (value == null) value = ""; element.put(fieldName, value); } else if ("int".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getInt(columnName))); } else if ("long".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getLong(columnName))); } else if ("float".equals(fieldType)) { element.put(fieldName, String.valueOf(rs.getFloat(columnName))); } } list.add(element); } return list; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute queryBySql mothod :\n" + e); throw new SysException("SQLException while execute queryBySql mothod :\n" + e); } finally { closeResultSet(rs); closeStatement(stmt); closeConnection(dbConnection); } } public static int getRowCountBySql(String sql) throws SysException { Connection dbConnection = null; Statement stmt = null; ResultSet rs = null; 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 TABLE_NAME, OPERATOR_TYPE, DATA_BEFORE_MODIFY, DATA_AFTER_MODIFY, HOSTIP, MODIFY_STAFF, MODIFY_TIME, REMARK FROM WAP_MODIFY_LOG"; return queryBySql(sql); } public static Collection queryAll(int beginRow, int endRow) throws SysException { String sql = "SELECT TABLE_NAME, OPERATOR_TYPE, DATA_BEFORE_MODIFY, DATA_AFTER_MODIFY, HOSTIP, MODIFY_STAFF, MODIFY_TIME, REMARK FROM WAP_MODIFY_LOG"; return queryBySql(sql, beginRow, endRow); } public static int getRowCountOfAll() throws SysException { String sql = "SELECT COUNT(*) FROM WAP_MODIFY_LOG"; return getRowCountBySql(sql); } public static ModifyLogModel toModel(Hashtable element) { ModifyLogModel model = new ModifyLogModel(); model.setTableName((String)element.get("tableName")); model.setOperatorType((String)element.get("operatorType")); model.setDataBeforeModify((String)element.get("dataBeforeModify")); model.setDataAfterModify((String)element.get("dataAfterModify")); model.setHostip((String)element.get("hostip")); model.setModifyStaff((String)element.get("modifyStaff")); model.setModifyTime((Timestamp)element.get("modifyTime")); model.setRemark((String)element.get("remark")); 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 WAP_SEQUENCE WHERE TABLE_NAME = 'WAP_MODIFY_LOG'"; Connection dbConnection = null; Statement stmt = null; ResultSet rs = null; int lastValue = 1; try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); rs = stmt.executeQuery(sql);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -