📄 groupsmtpdao.java
字号:
model.setSmtpUserName((String)element.get("smtpUserName")); model.setSmtpUserPwd((String)element.get("smtpUserPwd")); 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_GROUP_SMTP'"; 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 WAP_SEQUENCE SET LAST_VALUE = " + (lastValue + incrementBy) + " WHERE TABLE_NAME = 'WAP_GROUP_SMTP'"; stmt.executeUpdate(sql); }else{ sql = "INSERT INTO WAP_SEQUENCE (TABLE_NAME, LAST_VALUE, MIN_VALUE, MAX_VALUE, INCREMENT_BY, CYCLE) VALUES ('WAP_GROUP_SMTP', 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(GroupSmtpModel model) { String sql = ""; if (Database.dbType == DBType.ORACLE) { sql = "INSERT INTO WAP_GROUP_SMTP (GROUP_ID, SMTP_URL, SMTP_USER_NAME, SMTP_USER_PWD) VALUES (" + model.getGroupId() + ", '" + Function.writeDBEncode(model.getSmtpUrl()) + "', '" + Function.writeDBEncode(model.getSmtpUserName()) + "', '" + Function.writeDBEncode(model.getSmtpUserPwd()) + "')"; } else if (Database.dbType == DBType.SQLSERVER) { sql = "INSERT INTO WAP_GROUP_SMTP (GROUP_ID, SMTP_URL, SMTP_USER_NAME, SMTP_USER_PWD) VALUES (" + model.getGroupId() + ", '" + Function.writeDBEncode(model.getSmtpUrl()) + "', '" + Function.writeDBEncode(model.getSmtpUserName()) + "', '" + Function.writeDBEncode(model.getSmtpUserPwd()) + "')"; } else if (Database.dbType == DBType.MYSQL) { sql = "INSERT INTO WAP_GROUP_SMTP (GROUP_ID, SMTP_URL, SMTP_USER_NAME, SMTP_USER_PWD) VALUES (" + model.getGroupId() + ", '" + Function.writeDBEncode(model.getSmtpUrl()) + "', '" + Function.writeDBEncode(model.getSmtpUserName()) + "', '" + Function.writeDBEncode(model.getSmtpUserPwd()) + "')"; } return sql; } protected static boolean isValidData(GroupSmtpModel 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)) { GroupSmtpModel model=new GroupSmtpModel(); model.setGroupId(1); model.setSmtpUrl("abc"); model.setSmtpUserName("abc"); model.setSmtpUserPwd("abc"); GroupSmtpModel groupSmtpModel = GroupSmtpBean.insert(model); }else if ("queryBySql".equalsIgnoreCase(action)){ Collection coll = GroupSmtpBean.queryBySql("SELECT * FROM WAP_GROUP_SMTP"); }else if ("getRowCountBySql".equalsIgnoreCase(action)){ int rowCount = GroupSmtpBean.getRowCountBySql("SELECT COUNT(*) FROM WAP_GROUP_SMTP"); System.out.println("rowCount = " + rowCount); }else if ("queryAll".equalsIgnoreCase(action)){ Collection coll = GroupSmtpBean.queryAll(); Iterator it = coll.iterator(); while ( it.hasNext() ) { Hashtable element = (Hashtable)it.next(); String groupId = (String)element.get("groupId"); String smtpUrl = (String)element.get("smtpUrl"); String smtpUserName = (String)element.get("smtpUserName"); String smtpUserPwd = (String)element.get("smtpUserPwd"); System.out.print("groupId = " + groupId + ",\t"); System.out.print("smtpUrl = " + smtpUrl + ",\t"); System.out.print("smtpUserName = " + smtpUserName + ",\t"); System.out.print("smtpUserPwd = " + smtpUserPwd + "\n"); } }else if ("getRowCountOfAll".equalsIgnoreCase(action)){ int rowCount = GroupSmtpBean.getRowCountOfAll(); System.out.println("rowCount = " + rowCount); } }}/*int groupId = (model==null?0:model.getGroupId());String smtpUrl = (model==null?"":model.getSmtpUrl());String smtpUserName = (model==null?"":model.getSmtpUserName());String smtpUserPwd = (model==null?"":model.getSmtpUserPwd());int groupId = PageUtil.parseIntField(request.getParameter("groupId"), "groupId", false, 0, *);String smtpUrl = PageUtil.parseStringField(request.getParameter("smtpUrl"), "smtpUrl", false, 199);String smtpUserName = PageUtil.parseStringField(request.getParameter("smtpUserName"), "smtpUserName", false, 29);String smtpUserPwd = PageUtil.parseStringField(request.getParameter("smtpUserPwd"), "smtpUserPwd", false, 19);int groupId = PageUtil.parseIntField(request.getParameter("groupId"), "groupId", false, 0, 2147483647);String smtpUrl = PageUtil.parseStringField(request.getParameter("smtpUrl"), "smtpUrl", true, 200);String smtpUserName = PageUtil.parseStringField(request.getParameter("smtpUserName"), "smtpUserName", true, 30);String smtpUserPwd = PageUtil.parseStringField(request.getParameter("smtpUserPwd"), "smtpUserPwd", true, 20);String groupId = (model==null?"0":""+model.getGroupId());String smtpUrl = (model==null?"":""+model.getSmtpUrl());String smtpUserName = (model==null?"":""+model.getSmtpUserName());String smtpUserPwd = (model==null?"":""+model.getSmtpUserPwd());Collection coll = GroupSmtpBean.queryAll((pageNum-1) * pageRow + 1, pageNum * pageRow);Iterator it = coll.iterator();while ( it.hasNext() ) { Hashtable element = (Hashtable)it.next(); GroupSmtpModel groupSmtpModel = GroupSmtpBean.toModel(element); int groupId = groupSmtpModel.getGroupId(); String smtpUrl = groupSmtpModel.getSmtpUrl(); String smtpUserName = groupSmtpModel.getSmtpUserName(); String smtpUserPwd = groupSmtpModel.getSmtpUserPwd(); excel.setCellData(new ExcelCell(ExcelUtil.INT_CELL_TYTE, currRow, currCol++), groupId+""); excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), smtpUrl+""); excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), smtpUserName+""); excel.setCellData(new ExcelCell(ExcelUtil.STRING_CELL_TYTE, currRow, currCol++), smtpUserPwd+"");*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -