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

📄 querydatabase.java

📁 彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package mmsproject;

import java.sql.*;
import java.io.*;
import java.util.*;
import mmsproject.model.*;
import mmsproject.common.GetProperties;
import mmsproject.common.ConnectionManager;
import java.text.*;

/**
 * <p>Title: 彩信发送接收项目</p>
 * <p>Description: 用于查询数据库中有无需要发送的信息,如果有,则将其发送</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author tomato
 * @version 1.0
 */

public class QueryDataBase implements Runnable {

    //控制线程执行的标记
    public boolean boolFlag = true;

    public QueryDataBase() {
    }

    /**
     * 用于轮询数据库的线程执行的方法
     */
    public void run() {
           Connection conn = null;
           CallableStatement stmt = null;
        //不断查询数据库有无需要发送的彩信
        while (boolFlag) {

          //不断执行接收分发存储过程 sp_get_receive
           try {
             conn = ConnectionManager.getSqlConnection();
             stmt = conn.prepareCall("{call sp_get_receive}");
             stmt.execute();

           } catch (Exception e) {
                      e.printStackTrace();
                      String temp = FrmMMSManage.m_txtStatus.getText();
                      FrmMMSManage.m_txtStatus.setText(temp+e.getMessage() + "get_all_receive错误:" + "\n" + temp);
                  }


            //检测多行文本框中的数据大小,如果过大则清空
            if (FrmMMSManage.m_txtStatus.getText().length() > 100000) {
                FrmMMSManage.m_txtStatus.setText("");
            }

            //1.取得需要发送的彩信
            Vector vData = new Vector();
            try {

                vData = searchForSend();

            } catch (Exception ex) {
                ex.printStackTrace();
            }
            //3.将重数据库中取得的信息发送出去,并且将其存入表TB_SEND,并通过SendId将缓存表中发送未超时的数据删除
            //取回缓存数据
            if (!vData.isEmpty()) {
                Enumeration enuData = vData.elements();
                while (enuData.hasMoreElements()) {

                    SendData sd = (SendData) enuData.nextElement();

                    //发送数据到彩信中心
                    MyMMSender sender = new MyMMSender();
                    sender.send(sd);
                }
            }

            //每隔5秒运行一次
            try {
                //设置查询数据库时间间隔
                //此处应该替换为读取配置文件的属性取得
                Thread.sleep(Integer.parseInt(GetProperties.QueryDelay));
            } catch (Exception w) {
                String temp = FrmMMSManage.m_txtStatus.getText();
                FrmMMSManage.m_txtStatus.setText(temp + w.getMessage() +
                        "用于不断查询数据库的线程执行的方法" + "\n");
            }
        }
    }

    /**
     * 通过SendId将缓存表中的数据删除
     * @param nSendId int
     */
    public static void deleteTempData(int nSendId) {
        //创建查询语句
        String strSql = "DELETE TB_MMS_SEND_TEMP WHERE SendID=" + nSendId;
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = ConnectionManager.getSqlConnection();
            stmt = conn.createStatement();
            stmt.execute(strSql);
        } catch (Exception ex) {
            //显示出错信息
            //ex.printStackTrace();
            String temp = FrmMMSManage.m_txtStatus.getText();
            FrmMMSManage.m_txtStatus.setText(ex.getMessage() + "Querybase查询数据库" + "\n" + temp);
        } finally {
            //关闭数据库连接
            ConnectionManager.closeSqlStatement(stmt);
            ConnectionManager.closeSqlConnection(conn);
        }
    }

    /**
     * 通过SendId将缓存表(TB_SEND_TEMP)中的数据存入历史表(TB_SEND)中
     * @param nSendId int
     */
    public static void moveTempData(int nSendId) {
        //创建查询语句
        //insert into tb_send_temp select * from tb_send where sendid=
        //String strSql = "SELECT * INTO TB_SEND FROM TB_SEND_TEMP WHERE SendId=" + nSendId;
        String strSql = "insert into TB_MMS_SEND select * from TB_MMS_SEND_TEMP where SendId=" +
                nSendId;
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = ConnectionManager.getSqlConnection();
            stmt = conn.createStatement();
            stmt.execute(strSql);
        } catch (Exception ex) {
            //显示出错信息(迟点再改...)
            ex.printStackTrace();
            String temp = FrmMMSManage.m_txtStatus.getText();
            FrmMMSManage.m_txtStatus.setText(ex.getMessage() + "Querybase查询数据库" + "\n" + temp);
        } finally {
            //关闭数据库连接
            ConnectionManager.closeSqlStatement(stmt);
            ConnectionManager.closeSqlConnection(conn);
        }
    }

    /**
     * 寻找需要发送的信息(将所有需要发送的信息缓存到vector中)
     */
    private Vector searchForSend() {
        //创建vector对象用于缓存取得的数据
        Vector vData = new Vector();
        String nowTime=new SimpleDateFormat("hh").format(new java.util.Date());
        //创建查询语句
        //--------------------------------------------------------------------------//
        //这段sql语句需要修改//
        String strSqlSend = "SELECT"
                + " top 5 s.*,"
                + " sys.contentpath+service.contentpath+pic.ContentPath as PicPath,"
                + " sys.contentpath+service.contentpath+ring.ContentPath as RingPath,"
                + " sys.contentpath+service.contentpath+mix.ContentPath as MixPath"
                + " FROM "
                + " TB_MMS_SEND_TEMP s "
                + " left join"
                + " TB_MMS_PIC_CONTENT pic"
                + " on"
                + " s.PicContentID=pic.PicID"
                + " left join"
                + " TB_MMS_RING_CONTENT ring"
                + " on"
                + " s.RingContentID=ring.RingID"
                + " left join"
                + " TB_MMS_MIX_CONTENT mix"
                + " on"
                + " s.MixContentID=mix.MixID"
                + " left join TB_SERVICES service"
                + " on"
                + " s.MyServiceCode=service.MyServiceCode,"
                + " TB_SYSTEM_DEFINED sys"
                + " WHERE "
                + " s.FlagSend=? "
                + " AND s.TimeToSend<=getdate()  order by s.sendID";
        if(Integer.parseInt(nowTime)<9 || Integer.parseInt(nowTime)>21){
            strSqlSend = "SELECT"
                            + " top 5 s.*,"
                            + " sys.contentpath+service.contentpath+pic.ContentPath as PicPath,"
                            + " sys.contentpath+service.contentpath+ring.ContentPath as RingPath,"
                            + " sys.contentpath+service.contentpath+mix.ContentPath as MixPath"
                            + " FROM "
                            + " TB_MMS_SEND_TEMP s "
                            + " left join"
                            + " TB_MMS_PIC_CONTENT pic"
                            + " on"
                            + " s.PicContentID=pic.PicID"
                            + " left join"
                            + " TB_MMS_RING_CONTENT ring"
                            + " on"
                            + " s.RingContentID=ring.RingID"
                            + " left join"
                            + " TB_MMS_MIX_CONTENT mix"
                            + " on"
                            + " s.MixContentID=mix.MixID"
                            + " left join TB_SERVICES service"
                            + " on"
                            + " s.MyServiceCode=service.MyServiceCode,"
                            + " TB_SYSTEM_DEFINED sys"

⌨️ 快捷键说明

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