java--数据采集系统

上传人:第*** 文档编号:34243954 上传时间:2018-02-22 格式:DOC 页数:12 大小:38KB
返回 下载 相关 举报
java--数据采集系统_第1页
第1页 / 共12页
java--数据采集系统_第2页
第2页 / 共12页
java--数据采集系统_第3页
第3页 / 共12页
java--数据采集系统_第4页
第4页 / 共12页
java--数据采集系统_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《java--数据采集系统》由会员分享,可在线阅读,更多相关《java--数据采集系统(12页珍藏版)》请在金锄头文库上搜索。

1、java-数据采集系统 分类: Android 开发 java 讨论区 2011-09-04 17:18 173 人阅读 评论(0) 收藏 举报 Gather 采集类:package com.briup.woss.client.impl;import java.io.*;import java.sql.Timestamp;import java.util.*;import com.briup.pojos.BIDR;import com.briup.woss.client.Gather;public class GatherImpl implements Gather private stati

2、c Map map=new HashMap();/* 读取 up.dat 文件,up.dat 文件存放的是用户没下线的信息,* 规定格式为:loginIp,userinfo;*/private static FileReader fr;private static BufferedReader br;statictryfr=new FileReader(data/up.dat);br=new BufferedReader(fr);String str;while(str=br.readLine()!=null)String subStr=str.split(;);for(int i=0;i g

3、ather() throws Exception Collection c=new ArrayList();FileReader fr=new FileReader(data/radwtmp);BufferedReader br=new BufferedReader(fr);int point=readPointFile();int p=point;String str=null;int temp=1;/* 读取 point 文件来确定从哪一条记录开始读*/while(str=br.readLine()!=null)if(temp c) throws Exception Socket clie

4、nt=new Socket(127.0.0.1,9001);ObjectOutputStream object=new ObjectOutputStream(client.getOutputStream();object.writeObject(c);public void setProperties(Properties pop) client 端的 Main 类:package com.briup.woss.client;import java.util.Collection;import com.briup.pojos.BIDR;import com.briup.util.BackUP;

5、import com.briup.util.Configuration;import com.briup.util.Logger;import static com.briup.util.impl.ConfigurationImpl.*;public class Main public static Configuration conf =getConfiguration();public static void main(String args) Logger logger = null;Gather gather = null;BackUP backup = null;Client cli

6、ent = null;Collection con = null;try logger = conf.getClientLogger();logger.info(客户端开始启动);gather = conf.getGather();logger.info(准备采集);long a=System.currentTimeMillis();con = gather.gather();System.out.println(System.currentTimeMillis()-a);logger.info(采集成功);backup = conf.getBackup();try client = conf

7、.getClient();logger.info(准备发送 );client.send(con);logger.info(发送成功!); catch (Exception e) logger.error(e.getMessage();logger.info(准备备份);/backup.load();backup.store(con);logger.info(备份成功); catch (Exception e1) e1.printStackTrace();logger.error(e1.getMessage();logger.warn(采集失败);ServerImpl 类:package com

8、.briup.woss.server.impl;import .ServerSocket;import .Socket;import java.util.*;import java.io.*;import com.briup.pojos.BIDR;import com.briup.woss.server.DBStore;import com.briup.woss.server.Server;import com.sun.org.apache.xml.internal.serialize.Printer;public class ServerImpl implements Server publ

9、ic void revicer(DBStore dbstore) throws Exception Collectionc=new ArrayList();ServerSocket server=new ServerSocket(9001);Socket socket=server.accept();ObjectInputStream object=new ObjectInputStream(socket.getInputStream();c=(Collection)object.readObject();for(BIDR bidr:c)System.out.println(bidr);dbs

10、tore.saveToDB(c);object.close();socket.close();server.close();public void setProperties(Properties pop) / TODO Auto-generated method stubDBStoreImpl 类package com.briup.woss.server.impl;import static mon.ConnectionFactory.*;import java.sql.DriverManager;import java.util.Collection;import java.util.Pr

11、operties;import com.briup.pojos.BIDR;import com.briup.woss.server.DBStore;import java.sql.*;public class DBStoreImpl implements DBStore private static Connection con;staticcon=getConnection();public void saveToDB(Collection c) throws ExceptionPreparedStatement psmt=null;CallableStatement stmt;/设置为自动

12、提交事物con.setAutoCommit(false);/插入到 t_detail_x 中for(BIDR bidr:c)String sql=insert into t_detail_+bidr.getLogin_date().getDate()+ values(?,?,?,?,?,?);psmt=con.prepareStatement(sql);psmt.setString(1, bidr.getAAA_login_name();psmt.setString(2, bidr.getLogin_ip();psmt.setTimestamp(3, bidr.getLogin_date();

13、psmt.setTimestamp(4, bidr.getLogout_date();psmt.setString(5, bidr.getNAS_ip();psmt.setInt(6, bidr.getTime_deration();psmt.execute();mit();/调用 daypro 存储过程执行对 t_day_x 插入数据stmt=con.prepareCall(call daypro);stmt.execute();/调用 monthpro 存储过程执行对 t_month_x 插入数据stmt=con.prepareCall(call monthpro);stmt.execut

14、e();stmt.close();/调用 yearpro 存储过程执行对 t_year_x 插入数据/*CallableStatement stmt3=con.prepareCall(call yearpro);stmt3.execute();stmt3.close();*/psmt.close();con.close();public void setProperties(Properties pop) / TODO Auto-generated method stubserver 端的 Main 类:package com.briup.woss.server;import com.briu

15、p.util.Configuration;import com.briup.util.Logger;import static com.briup.util.impl.ConfigurationImpl.*;public class Main /* * 服务器端的程序入口*/public static Configuration conf =getConfiguration();public static void main(String args) DBStore dbstore = null;Server server = null;Logger logger=null;try dbstore = conf.getDBStore();server = conf.getServer();logger=conf.getServerLogger();logger.info(服务端等待接收数据 );server.revicer(dbstore);logger.info(服务端接收数据成功 ); catch (Exception e) logger.error(e.getMessage();logger.warn(服务端接收数据失败);

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号