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

📄 smsservicedao.java

📁 采用JAVA开发
💻 JAVA
字号:
package com.gctech.sms.dao;

import java.util.Collection;
import java.util.Map;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import org.apache.log4j.Logger;
import com.gctech.sms.util.ConnectionManager;
import com.gctech.sms.vo.SmsServiceObject;
import java.sql.PreparedStatement;
import java.sql.*;
import java.util.ArrayList;
import com.gctech.sms.dao.IDGenerator;
/**
 * <p>Title: SP管理模块</p>
 * <p>Description: 负责增、删除、修改Sp数据</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: gctech</p>
 * @author wengjl
 * @version $Id: SmsServiceDao.java,v 1.3 2004/04/22 01:46:30 wanghb Exp $
 */

public class SmsServiceDao {
  public static int add(SmsServiceObject obj){
    int rt = -1;
    Connection con = null;
    PreparedStatement pstmt = null;
    try{
      con = ConnectionManager.getInstance().getConnection(MOCommandDao.class);
      pstmt = con.prepareStatement(
          "insert into smsservice(ID,FEETYPE,FEECODE,SUBTYPE)values(?,?,?,?)");
      pstmt.setString(1, obj.getID());
      pstmt.setString(2, obj.getFeeType());
      pstmt.setString(3, obj.getFeeCode());
      pstmt.setInt(4, obj.getSubType());
      pstmt.execute();
      rt = 0;
    }catch( Throwable e ){
      logger.error(e, e);
    }finally{
      if ( pstmt != null ){
        try {
          pstmt.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      return rt;
    }
  }


  public static int addSms(SmsServiceObject info){//增加数据
    Connection con = null;
    PreparedStatement pstmt = null;
    int rs = 0;
    try {
      con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
      String sql = " INSERT INTO smsservice ( smsservice.ID,smsservice.feetype,smsservice.feecode,smsservice.subtype,smsservice.msgformat,smsservice.needreply ) VALUES ( ?, ?, ? , ?, ?, ?)  ";
      pstmt = con.prepareStatement(sql.toString());//往数据库增加数据
      //得到ID
      //String id = IDGenerator.nextId();
      String id = info.getID();
      if (id == null){
        pstmt.setNull(1, Types.VARCHAR);
      }else{
        pstmt.setString(1, id);
      }
      if (info.getFeeType()==null){
        pstmt.setNull(2, Types.VARCHAR);
      }else{
        pstmt.setString(2, info.getFeeType());
      }
      if (info.getFeeCode()==null){
        pstmt.setNull(3, Types.VARCHAR);
      }else{
        pstmt.setString(3, info.getFeeCode());
      }
      //if (info.getSubType()==0){
      //  pstmt.setNull(4, Types.INTEGER);
      //}else{
        pstmt.setInt(4, info.getSubType());
     // }
     // if (info.getMsgFormat()==null){
     //   pstmt.setNull(5, Types.VARCHAR);
     // }else{
        pstmt.setInt(5, info.getMsgFormat());
     // }
     // if (info.getNeedReply()==null){
     //   pstmt.setNull(6, Types.VARCHAR);
     // }else{
        pstmt.setInt(6, info.getNeedReply());
      //}

     rs = pstmt.executeUpdate();
    }
    catch (Throwable ex) {
      logger.error(ex, ex);
    }finally{
      if ( pstmt != null ){
        try {
          pstmt.close();
        }
        catch (SQLException ex1) {
          logger.error(ex1, ex1);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (SQLException ex1) {
          logger.error(ex1, ex1);
        }
      }
    }
    return rs;
  }
  public SmsServiceObject[] getAllSms(SmsServiceObject infovalue) throws SQLException {//查询所有数据
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        ArrayList list = new ArrayList();
        try{
          con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
          StringBuffer sql = new StringBuffer("select a.id,a.feetype,a.feecode,a.subtype,a.msgformat,");
          sql.append( "a.needreply");
          sql.append( " from smsservice a");
          sql.append( " where 1=1");
          if (infovalue!=null && infovalue.getID()!=null && !infovalue.getID().equals("")){
            sql.append( " and a.id='" + infovalue.getID() + "'");
          }
          logger.debug(sql.toString());
          pstmt = con.prepareStatement(sql.toString());
          rs = pstmt.executeQuery();
          while (rs.next()){
            SmsServiceObject model = new SmsServiceObject();
            String id = rs.getString("id");
            if (!rs.wasNull()) model.setID(id);
            String feetype = rs.getString("feetype");
            if (!rs.wasNull()) model.setFeeType(feetype);
            String feecode = rs.getString("feecode");
            if (!rs.wasNull()) model.setFeeCode(feecode);
            int subtype = rs.getInt("subtype");
            if (!rs.wasNull()) model.setSubType(subtype);
            byte msgformat = rs.getByte("msgformat");
            if (!rs.wasNull()) model.setMsgFormat(msgformat);
            int needreply = rs.getInt("needreply");
            if (!rs.wasNull()) model.setNeedReply(needreply);


            list.add(model);
          }
        }catch( Throwable e ){
          logger.error(e, e);
        }finally{
          if ( rs != null ){
            try {
              rs.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( pstmt != null ){
            try {
              pstmt.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( con != null ){
            try {
              con.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
        }
        //返回数据
        return (SmsServiceObject[])list.toArray(new SmsServiceObject[list.size()]);
  }
  public int deleteSms(SmsServiceObject infovalue) throws SQLException {//删除数据
        Connection con = null;
        PreparedStatement pstmt = null;
        int rs = 0 ;
        try{
          con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
          StringBuffer sql = new StringBuffer("delete from smsservice where 1=1 ");
          sql.append( "and smsservice.id = '" + infovalue.getID() + "'");

          pstmt = con.prepareStatement(sql.toString());
          rs = pstmt.executeUpdate();

        }catch( Throwable e ){
          logger.error(e, e);
        }finally{
          if ( pstmt != null ){
            try {
              pstmt.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( con != null ){
            try {
              con.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
        }
        //返回数据
        return rs;
  }
  public int updateSms(SmsServiceObject infovalue) throws SQLException {//更新数据
    Connection con = null;
    PreparedStatement pstmt = null;
    int rs = 0 ;
    try{
      con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
      StringBuffer sql = new StringBuffer("update smsservice set ");
      if (infovalue.getFeeType()!=null){
        if (infovalue.getFeeType().equals("@_@")){
            sql.append( " smsservice.feetype = null, ");
        }else{
            sql.append( " smsservice.feetype = '" + infovalue.getFeeType() + "',");
        }
      }
      if (infovalue.getFeeCode()!=null){
        if (infovalue.getFeeCode().equals("@_@")){
           sql.append( " smsservice.feecode = null, ");
        }else{
          sql.append( " smsservice.feecode = '" + infovalue.getFeeCode() + "',");
        }
      }

      sql.append( " smsservice.subtype = '" + infovalue.getSubType() + "',");

      sql.append( " smsservice.msgformat = '" + infovalue.getMsgFormat() + "',");

      sql.append( " smsservice.needreply = '" + infovalue.getNeedReply() + "',");

      sql.setLength(sql.length()-1);
      sql.append( " where 1=1");
      if (infovalue.getID()!=null){
        sql.append(" and smsservice.id = '" + infovalue.getID() + "'");
      }
      logger.debug(sql.toString());
      pstmt = con.prepareStatement(sql.toString());
      rs = pstmt.executeUpdate();

    }catch( Throwable e ){
      logger.error(e, e);
    }finally{
      if ( pstmt != null ){
        try {
          pstmt.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
    }
    //返回数据
    return rs;

  }

  static final Logger logger = Logger.getLogger(SmsServiceDao.class);
}

⌨️ 快捷键说明

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