channeldao.java

来自「WAP PUSH后台源码,WAP PUSH后台源码」· Java 代码 · 共 936 行 · 第 1/4 页

JAVA
936
字号
package com.sxit.wap.channel;import java.sql.*;import java.util.*;import com.sxit.wap.common.*;import com.sxit.wap.exception.*;public class ChannelDao {  public static String tableName = "WAP_CHANNEL";  public static ChannelModel insert(ChannelModel model) throws SysException,UpdateException,AppException {    if (!ChannelBean.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 ChannelModel insert(ChannelModel model, Connection dbConnection) throws SysException,UpdateException,AppException {    if (!ChannelBean.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 ChannelModel update(ChannelModel model) throws SysException,UpdateException,AppException {    if (!ChannelBean.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 ChannelModel update(ChannelModel model, Connection dbConnection) throws SysException,UpdateException,AppException {    if (!ChannelBean.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 id) throws SysException,UpdateException,AppException {    String sql = getDeleteSQL(id);    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 id, Connection dbConnection) throws SysException,UpdateException,AppException {    String sql = getDeleteSQL(id);    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[] ids) throws SysException,UpdateException,AppException {    String sql = getDeleteSQL(ids);    Connection dbConnection = null;    Statement stmt = null;    try {      dbConnection = getDBConnection();      stmt = dbConnection.createStatement();      int resultCount = stmt.executeUpdate(sql);      if ( resultCount != ids.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[] ids, Connection dbConnection) throws SysException,UpdateException,AppException {    String sql = getDeleteSQL(ids);    Statement stmt = null;    try {      stmt = dbConnection.createStatement();      int resultCount = stmt.executeUpdate(sql);      if ( resultCount != ids.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 ChannelModel findByPK(int id) throws SysException,FinderException {    String sql = getFindByPKSQL(id);    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 " + id);        throw new FinderException("No record for primary key " + id);      }      ChannelModel model = new ChannelModel();      model.setId(rs.getInt("ID"));      model.setCpId(rs.getInt("CP_ID"));      model.setChannelName(Function.readDBEncode(rs.getString("CHANNEL_NAME")));      model.setChannelDescribe(Function.readDBEncode(rs.getString("CHANNEL_DESCRIBE")));      model.setChannelUrl(Function.readDBEncode(rs.getString("CHANNEL_URL")));      model.setChannelAccess(rs.getInt("CHANNEL_ACCESS"));      model.setChannelSubscribe(rs.getInt("CHANNEL_SUBSCRIBE"));      model.setChannelStatus(rs.getInt("CHANNEL_STATUS"));      model.setChannelRegdate(rs.getTimestamp("CHANNEL_REGDATE"));      model.setChannelType(rs.getInt("CHANNEL_TYPE"));      model.setChannelAppear(rs.getInt("CHANNEL_APPEAR"));      model.setChannelTrade(rs.getInt("CHANNEL_TRADE"));      model.setChannelFree(rs.getInt("CHANNEL_FREE"));      model.setChannelTest(rs.getInt("CHANNEL_TEST"));      model.setChannelCode(Function.readDBEncode(rs.getString("CHANNEL_CODE")));      model.setSendMobile(rs.getInt("SEND_MOBILE"));      model.setChannelRemark(Function.readDBEncode(rs.getString("CHANNEL_REMARK")));      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;

⌨️ 快捷键说明

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