Java论坛网»Java技术»用java实现实时扫描数据库(例如:隔1秒扫描ACCESS数据库表)急:谢谢
用java实现实时扫描数据库(例如:隔1秒扫描ACCESS数据库表)急:谢谢
问?:
用java实现实时扫描数据库(例如:隔1秒扫描ACCESS数据库表)
能举个小例子更好再次谢谢
能举个小例子更好再次谢谢
答!: 1:
写个线程撒。
答!: 2:
package com.barcode;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: 将未发送及发送不成功的二维码压入管道</p>
* <p>Copyright: Copyright (c) 2006-1-7</p>
* <p>Company: 新宇龙信息技术有限公司</p>
* @author 增值事业部--贺建科
* @version 1.0
*/
public class PushNewBarcodeToPool
extends Engine {
//用于计数,是否到了给PUSH已发送但未取票的用户再次发送
public static int min = 0;
String sql = "";
//String sql = "select * from tom_ticket_order";
DbConnect db;
public PushNewBarcodeToPool() {
super("PushNewBarcodeToPool");
setDaemon(true);
db = new DbConnect();
}
public void run() {
while (true) {
Vector vResult = new Vector();
//获得需要发送二维码的用户 判断是否为PUSH已发送未取票需再次发送或是PUSH需要发送的
if(min ==0 || min == 360) {
sql = "select a.order_id, a.ticket_id, a.phone_no, a.order_name, a.order_time, a.ticket_counts, a.email, a.user_no, b.hold_no, b.area_code,b.ticket_no, b.eff_time, b.exp_time, b.barcode_name, b.barcode_addr, a.send_flag,b.company_no from tom_ticket_order a, tbc_ticket_info b where a.status='Q0A' and (a.send_flag not like 'Q0S%') and a.send_times<1 and a.ticket_id=b.ticket_id";
if(min == 360)
min= 0;
}else {
sql = "select a.order_id, a.ticket_id, a.phone_no, a.order_name, a.order_time, a.ticket_counts, a.email, a.user_no, b.hold_no, b.area_code,b.ticket_no, b.eff_time, b.exp_time, b.barcode_name, b.barcode_addr, a.send_flag,b.company_no from tom_ticket_order a, tbc_ticket_info b where a.status='Q0A' and (a.send_flag not like 'Q0S%' and a.send_flag not like 'Q0M%') and a.send_times<1 and a.ticket_id=b.ticket_id";
}
vResult = (Vector) db.executeSQL(sql);
int size = vResult.size();
//如果有需要发送二维码的用户
if (size > 0) {
System.out.println("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 发现有" + size +
"个电子票待发");
DataPool.LogPool.push("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 发现有" + size +
"个电子票待发");
for (int i = 0; i < size; i++) {
if (DataPool.PushPool.getSize() < 300) {
//将需要发送二维码的用户放入发送管道
DataPool.PushPool.push( (Barcode) vResult.get(i));
System.out.println("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 订单号为" +
( (Barcode) vResult.get(i)).
getOrder_id() +
"进入发送管道"
);
}
}
}
//所以用户都放入发送管道之后,清空结果对象
vResult.removeAllElements();
try {
min ++;
//睡眠一分钟
sleep(TimeConfig.TIME_ONE_MINUTE);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: 将未发送及发送不成功的二维码压入管道</p>
* <p>Copyright: Copyright (c) 2006-1-7</p>
* <p>Company: 新宇龙信息技术有限公司</p>
* @author 增值事业部--贺建科
* @version 1.0
*/
public class PushNewBarcodeToPool
extends Engine {
//用于计数,是否到了给PUSH已发送但未取票的用户再次发送
public static int min = 0;
String sql = "";
//String sql = "select * from tom_ticket_order";
DbConnect db;
public PushNewBarcodeToPool() {
super("PushNewBarcodeToPool");
setDaemon(true);
db = new DbConnect();
}
public void run() {
while (true) {
Vector vResult = new Vector();
//获得需要发送二维码的用户 判断是否为PUSH已发送未取票需再次发送或是PUSH需要发送的
if(min ==0 || min == 360) {
sql = "select a.order_id, a.ticket_id, a.phone_no, a.order_name, a.order_time, a.ticket_counts, a.email, a.user_no, b.hold_no, b.area_code,b.ticket_no, b.eff_time, b.exp_time, b.barcode_name, b.barcode_addr, a.send_flag,b.company_no from tom_ticket_order a, tbc_ticket_info b where a.status='Q0A' and (a.send_flag not like 'Q0S%') and a.send_times<1 and a.ticket_id=b.ticket_id";
if(min == 360)
min= 0;
}else {
sql = "select a.order_id, a.ticket_id, a.phone_no, a.order_name, a.order_time, a.ticket_counts, a.email, a.user_no, b.hold_no, b.area_code,b.ticket_no, b.eff_time, b.exp_time, b.barcode_name, b.barcode_addr, a.send_flag,b.company_no from tom_ticket_order a, tbc_ticket_info b where a.status='Q0A' and (a.send_flag not like 'Q0S%' and a.send_flag not like 'Q0M%') and a.send_times<1 and a.ticket_id=b.ticket_id";
}
vResult = (Vector) db.executeSQL(sql);
int size = vResult.size();
//如果有需要发送二维码的用户
if (size > 0) {
System.out.println("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 发现有" + size +
"个电子票待发");
DataPool.LogPool.push("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 发现有" + size +
"个电子票待发");
for (int i = 0; i < size; i++) {
if (DataPool.PushPool.getSize() < 300) {
//将需要发送二维码的用户放入发送管道
DataPool.PushPool.push( (Barcode) vResult.get(i));
System.out.println("[" + Log.getDateString() + " " +
Log.getTimeString() + "] 订单号为" +
( (Barcode) vResult.get(i)).
getOrder_id() +
"进入发送管道"
);
}
}
}
//所以用户都放入发送管道之后,清空结果对象
vResult.removeAllElements();
try {
min ++;
//睡眠一分钟
sleep(TimeConfig.TIME_ONE_MINUTE);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
答!: 3:
请问高手我想做成一个后台的监听程序,怎么样实现呢?能给出资料,方法或是代码,再一次拜谢了最好能说的详细点。
答!: 4:
这个其实用监听模式比较好,如果真要扫描,用后台线程即可
相关JAVA教程:
doGet()和doPost()的区别
关于JTable的问题,为什么表头显示不出来呀!!急,谢谢
dao中的bean与struts中的actionForm的疑问
关于j2ee的技术
有谁知道如何用javascript实现知道客户端使用的哪国语言
JSF+Spring+Hibernate写的一个应用程序,发布时报错....
struts+spring+hibernate的架沟,如果业务逻辑分析需要使用工厂方法模式,在SPRING的SERVICE里如何实现这个
求2006年6月16日的poi版本~~~~
关于applet的小问题
占个位子,送个5分
谁去过浙江支付宝 面试过?
请问这个问题难道是 Hibernate框架的一个缺憾吗?????