📄 channelfeedao.java
字号:
package com.sxit.wap.channelfee;import java.sql.*;import java.util.*;import com.sxit.wap.common.*;import com.sxit.wap.exception.*;public class ChannelFeeDao { public static String tableName = "WAP_CHANNEL_FEE"; public static ChannelFeeModel insert(ChannelFeeModel model) throws SysException,UpdateException,AppException { if (!ChannelFeeBean.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 ChannelFeeModel insert(ChannelFeeModel model, Connection dbConnection) throws SysException,UpdateException,AppException { if (!ChannelFeeBean.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 ChannelFeeModel update(ChannelFeeModel model) throws SysException,UpdateException,AppException { if (!ChannelFeeBean.isValidData(model)) { Debug.println(model.toString() + "\n" + "Illegal data values for update"); throw new AppException("Illegal data values for update"); } String sql = getUpdateSQL(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 UPDATE !! resultCount = " + resultCount); throw new UpdateException("ERROR in UPDATE !! resultCount = " + resultCount); } return model; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute update mothod :\n" + e); throw new SysException("SQLException while execute update mothod :\n" + e); } finally { closeStatement(stmt); closeConnection(dbConnection); } } public static ChannelFeeModel update(ChannelFeeModel model, Connection dbConnection) throws SysException,UpdateException,AppException { if (!ChannelFeeBean.isValidData(model)) { Debug.println(model.toString() + "\n" + "Illegal data values for update"); throw new AppException("Illegal data values for update"); } String sql = getUpdateSQL(model); Statement stmt = null; try { stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != 1 ) { Debug.println(sql + "\n" + "ERROR in UPDATE !! resultCount = " + resultCount); throw new UpdateException("ERROR in UPDATE !! resultCount = " + resultCount); } return model; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute update mothod :\n" + e); throw new SysException("SQLException while execute update mothod :\n" + e); } finally { closeStatement(stmt); } } public static void delete(int channelId, int feeType) throws SysException,UpdateException,AppException { String sql = getDeleteSQL(channelId, feeType); 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 DELETE !! resultCount = " + resultCount); throw new UpdateException("ERROR in DELETE !! resultCount = " + resultCount); } } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute delete mothod :\n" + e); throw new SysException("SQLException while execute delete mothod :\n" + e); } finally { closeStatement(stmt); closeConnection(dbConnection); } } public static void delete(int channelId, int feeType, Connection dbConnection) throws SysException,UpdateException,AppException { String sql = getDeleteSQL(channelId, feeType); Statement stmt = null; try { stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != 1 ) { Debug.println(sql + "\n" + "ERROR in DELETE !! resultCount = " + resultCount); throw new UpdateException("ERROR in DELETE !! resultCount = " + resultCount); } } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute delete mothod :\n" + e); throw new SysException("SQLException while execute delete mothod :\n" + e); } finally { closeStatement(stmt); } } public static void delete(int[] channelIds, int[] feeTypes) throws SysException,UpdateException,AppException { String sql = getDeleteSQL(channelIds, feeTypes); Connection dbConnection = null; Statement stmt = null; try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != channelIds.length ) { Debug.println(sql + "\n" + "ERROR in DELETE !! resultCount = " + resultCount); throw new UpdateException("ERROR in DELETE !! resultCount = " + resultCount); } } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute delete mothod :\n" + e); throw new SysException("SQLException while execute delete mothod :\n" + e); } finally { closeStatement(stmt); closeConnection(dbConnection); } } public static void delete(int[] channelIds, int[] feeTypes, Connection dbConnection) throws SysException,UpdateException,AppException { String sql = getDeleteSQL(channelIds, feeTypes); Statement stmt = null; try { stmt = dbConnection.createStatement(); int resultCount = stmt.executeUpdate(sql); if ( resultCount != channelIds.length ) { Debug.println(sql + "\n" + "ERROR in DELETE !! resultCount = " + resultCount); throw new UpdateException("ERROR in DELETE !! resultCount = " + resultCount); } } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute delete mothod :\n" + e); throw new SysException("SQLException while execute delete mothod :\n" + e); } finally { closeStatement(stmt); } } public static ChannelFeeModel findByPK(int channelId, int feeType) throws SysException,FinderException { String sql = getFindByPKSQL(channelId, feeType); Connection dbConnection = null; Statement stmt = null; ResultSet rs = null; try { dbConnection = getDBConnection(); stmt = dbConnection.createStatement(); rs = stmt.executeQuery(sql); if ( !rs.next() ) { Debug.println(sql + "\n" + "No record for primary key "); throw new FinderException("No record for primary key "); } ChannelFeeModel model = new ChannelFeeModel(); model.setChannelId(rs.getInt("CHANNEL_ID")); model.setFeeType(rs.getInt("FEE_TYPE")); model.setFeeCode(rs.getInt("FEE_CODE")); model.setFeeTimes(rs.getInt("FEE_TIMES")); model.setBeginDate(rs.getTimestamp("BEGIN_DATE")); model.setEndDate(rs.getTimestamp("END_DATE")); model.setCent(rs.getInt("CENT")); return model; } catch(SQLException e) { Debug.println(sql + "\n" + "SQLException while execute findByPK mothod :\n" + e); throw new SysException("SQLException while execute findByPK mothod :\n" + e); } finally { closeResultSet(rs); closeStatement(stmt); closeConnection(dbConnection); } } 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -