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

📄 objectdequeue.java

📁 中国联通短信通信协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        catch (Exception ex1) {
            //ex1.printStackTrace();
            statlog.error(ex1.getMessage());
        } finally {
            statlog.debug(" in save MT method flag=" + flag);
            if (!flag) {
                sqllog.info(sql+";");
            }
        }
        return flag;
    }
/*
    public Connection getTorqueConnection() {
        Connection conn = null;
        try {
            conn = Torque.getConnection();
        } catch (Exception ex) {
            ex.printStackTrace();
            mtlog.error(ex.getMessage());
        }
        return conn;
    }
/*/
//    private Connection getJDBCConnection() {
//        try {
//            if ( !this.checkConnection(connection) ) {
//                try {
//                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//                    connection = DriverManager.getConnection(
//                                 smsagent.databaseURL, smsagent.databaseUser, smsagent.databasePassword);
//                } catch (Exception e) {
//                    connection = null;
//                    statlog.error(e.getMessage());
//                } finally {
//                }
//            }
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            statlog.error(ex.getMessage());
//        }
//        return connection;
//    }


 private Connection getDBCPConnection() {
    try {
        return pool.getConnection();
    } catch (SQLException e) {
        statlog.error("数据库操作异常 - 无法获得连接 : \n" + e.getMessage());
        SmsGWIFGlobal.sendMonitor("D000001");
        return null;
    }
 }



   public boolean checkConnection(Connection conn){

       if (conn == null)
           return false;
       Statement stmt = null;
       ResultSet rs = null;
       try {
           stmt = conn.createStatement();
           rs = stmt.executeQuery("select sysdate from dual");
           if (rs.next())
               return true;
           else
               return false;
       }
       catch(Exception e){
           e.printStackTrace();
           return false;
       }
       finally{
           if(stmt != null){
            try {
                stmt.close();
            } catch (SQLException ex) { }
           }
           if(rs != null){
            try {
                rs.close();
            } catch (SQLException ex1) { }
           }
       }
   }

    private String getJDBCTime() {
        String xh = "";
        Calendar cal = Calendar.getInstance();
        xh = CTime.getTime(CTime.YYYYMMDDhhmmss, cal.getTimeInMillis());
        return xh;
    }
/*
    private int updateMTStatus(Stat stat) {
        int tmpflag = 0;
        String sql = "";
        boolean processFlag = false;
        boolean flag = false;
        Connection tmpconnection = getConnection();
        Statement sm = null;
        if (sm == null) {
            try {
                if (tmpconnection == null)
                    tmpconnection = getConnection();
                sm = tmpconnection.createStatement();
            } catch (Exception ex) {
                tmpflag = -1;
                ex.printStackTrace();
                statlog.error(ex.getMessage());
                return tmpflag;
            }
        }
        ResultSet result = null;
        //得到数据库中没有匹配上的数据
        sql =
            "select vc2msgid2 from sms_mtrecord where datreport is null and datsendtime>sysdate -1 and vc2desttermid='" +
            stat.getDestTermID() + "'";
        try {
            result = sm.executeQuery(sql);
            while (result.next()) {
                String tmpMsgId = result.getString(1);
                tmpMsgId = tmpMsgId.substring(0, 10);
                String statMsgId = stat.getMsgID().substring(0, 10);
                int tmpValue = java.lang.Math.abs(Integer.parseInt(tmpMsgId) - Integer.parseInt(statMsgId));
                if (tmpValue < 10) {
                    processFlag = true;
                    stat.setMsgID(result.getString(1));
                }
            }
            result.close();
        } catch (Exception e) {
            try {
                result.close();
            } catch (Exception w) {}
            tmpflag = -1;
            return tmpflag;
        }

        if (processFlag) {
            //修改数据库中的数据
            String update = "";
            String status = stat.getStat().trim().equalsIgnoreCase("DELIVRD") ?
                            "R" : "O:" + stat.getStat();
            if (stat.getSubmitTime() != null && stat.getDoneTime().length() > 0)

                update = "update SMS_MTRECORD set VC2STATUS='" + status +
                         "',DATREPORT=to_date('" +
                         "20" + stat.getDoneTime() +
                         "','yyyymmddhh24=mi') where VC2MSGID2='" + stat.getMsgID() +
                         "'";
            else
                update =
                    "update SMS_MTRECORD set VC2STATUS='" + status +
                    "',DATREPORT=sysdate where VC2MSGID2='" +
                    stat.getMsgID() + "'";
            try {
                tmpflag = sm.executeUpdate(update);
                sm.close();

            } catch (SQLException ex2) {
                tmpflag = -1;
                ex2.printStackTrace();
            } catch (Exception ex1) {
                tmpflag = -1;
                ex1.printStackTrace();
            }
        }
        return tmpflag;
    }
*/
    //保存失败的纪录
    private boolean SaveFalStatus(Stat stat) {
        boolean flag = false;
        String sql = "";
        try {
            //向数据库中写入下行纪录
            try {
                String vc2msgid2 = "";
                try{
                    vc2msgid2 = stat.getMsgID();
                }catch(Exception e){ }

                String vc2status = "";
                try{
                    if ("DELIVRD".equals(stat.getStat())) {
                        vc2status = "R";
                    } else {
                        vc2status = "O:" + stat.getStat();
                    }
                }catch(Exception e){ }

                String submitTime = "";
                try{
                    if (stat.getSubmitTime() != null && stat.getSubmitTime().length() > 0) {
                        submitTime = "20" + stat.getSubmitTime() + "00";
                    } else {
                        submitTime = getJDBCTime();
                        submitTime = submitTime.substring(0, 14);
                    }
                }catch(Exception e){ }

                String DatReport = "";
                try {
                    DatReport = getJDBCTime();
                    DatReport = DatReport.substring(0, 14);
                } catch (Exception w) {}

                String vc2DestTermID = "";
                try{
                    vc2DestTermID = stat.getDestTermID();
                }
                catch(Exception e){ }

                int gatewayid = 0;
                try {
                    gatewayid = Integer.parseInt(stat.getGatewayID());
                } catch (Exception w) {
                    gatewayid = 0;
                    w.printStackTrace();
                    statlog.error("网关编号错误 : " + stat.getGatewayID());
                }

                sql =
                    "insert into sms_falmtrecord(VC2MSGID2,NUMGATEWAYID,VC2DESTTERMID,DATSENDTIME,DATREPORT,NUMMTID,VC2STATUS) " +
                    "values('" + vc2msgid2 + "'," + gatewayid + ",'" + vc2DestTermID + "',to_date('" + submitTime +
                    "','YYYY/MM/DD HH24:MI:SS'),to_date('" + DatReport + "','YYYY/MM/DD HH24:MI:SS')," + "sms_falmtrecord_seq.nextval" + ",'" +
                    vc2status + "')";

                if( this.executeUpdate(sql) > 0 ){
                    flag = true;
                }

            }
            catch (Exception ex2) {
                //ex2.printStackTrace();
                statlog.error(ex2.getMessage());
            }
        } finally {
                statlog.debug(" in save falmtstatus=" + flag);
            if(!flag){
                sqllog.info(sql+";");
            }

        }
        return flag;
    }


    public int executeUpdate(String sql){
        Connection failconn = null;
        Statement sm = null;
        int result = -1;

        try {
            failconn = getDBCPConnection();

            if (failconn != null) {
                sm = failconn.createStatement();
                result = sm.executeUpdate(sql);
            }
        } catch (Exception e) {
            e.printStackTrace();
            statlog.error("数据库操作异常 - " + e.getMessage() + "\nsql: " + sql);
            SmsGWIFGlobal.sendMonitor("D000001");
        } finally {
            try {
                if (failconn != null) {
                    failconn.close();
                }
                if (sm != null) {
                    sm.close();
                }
            } catch (SQLException e) {
                statlog.error("数据库关闭异常 - " + e.getMessage());
            }
        }

        return result;
    }


    public static void main(String args[]){
        System.out.println("Start");
       System.out.println(CTime.getTime(10).substring(6, 10));
       Thread t = new Thread(new ObjectDeQueue());
       t.start();
       System.out.println("over");
    }
}

⌨️ 快捷键说明

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