java数据采集系统Word格式.docx

上传人:b****6 文档编号:20855570 上传时间:2023-01-26 格式:DOCX 页数:9 大小:16.91KB
下载 相关 举报
java数据采集系统Word格式.docx_第1页
第1页 / 共9页
java数据采集系统Word格式.docx_第2页
第2页 / 共9页
java数据采集系统Word格式.docx_第3页
第3页 / 共9页
java数据采集系统Word格式.docx_第4页
第4页 / 共9页
java数据采集系统Word格式.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

java数据采集系统Word格式.docx

《java数据采集系统Word格式.docx》由会员分享,可在线阅读,更多相关《java数据采集系统Word格式.docx(9页珍藏版)》请在冰豆网上搜索。

java数据采集系统Word格式.docx

);

br=newBufferedReader(fr);

Stringstr;

while((str=br.readLine())!

=null)

StringsubStr[]=str.split("

;

"

for(inti=0;

i<

subStr.length;

i++)

StringsubS[]=subStr[i].split("

"

map.put(subS[0],subS[1]);

}

catch(Exceptione)

e.printStackTrace();

finally

br.close();

fr.close();

//采集数据

publicCollection<

BIDR>

gather()throwsException{

Collection<

c=newArrayList<

();

FileReaderfr=newFileReader("

data/radwtmp"

BufferedReaderbr=newBufferedReader(fr);

intpoint=readPointFile();

intp=point;

Stringstr=null;

inttemp=1;

*读取point文件来确定从哪一条记录开始读

if(temp<

=p)

temp++;

continue;

point++;

Stringstr1[]=str.split("

[|]+"

if(str1[2].equals("

7"

))

map.put(str1[4],str);

elseif(str1[2].equals("

8"

Stringsub=(String)map.get(str1[4]);

if(sub!

Stringinfo[]=sub.split("

Stringlogin_name=info[0].replace("

#"

"

//去除用户名前面的"

BIDRbidr=newBIDR();

//得到登陆用户名

bidr.setAAA_login_name(login_name);

//得到登陆IP

bidr.setLogin_ip(info[4]);

//得到NAS的IP

bidr.setNAS_ip(info[1]);

*创建Timestamp类型的ts1(上线),ts2(下线)

*/

Timestampts1=newTimestamp(Long.parseLong(info[3]+"

000"

));

Timestampts2=newTimestamp(Long.parseLong(str1[3]+"

//得到上线时间

bidr.setLogin_date(ts1);

//得到下线时间

bidr.setLogout_date(ts2);

//得到上网时间,以分钟计算

intsecondTime=Integer.parseInt(str1[3])-Integer.parseInt(info[3]);

intminuTime=secondTime/60+1;

if(secondTime%60==0)

minuTime=secondTime/60;

bidr.setTime_deration(minuTime);

c.add(bidr);

map.remove(str1[4]);

if(point%100==0)

break;

updatePointFile(point);

//更新书签

updateUpFile();

returnc;

//读取point书签

publicintreadPointFile()throwsException

FileReaderfis=newFileReader("

data/point.dat"

BufferedReaderbr=newBufferedReader(fis);

Stringstr=br.readLine();

if(str==null)

return0;

intpoint=Integer.parseInt(str);

returnpoint;

//更新point书签

publicvoidupdatePointFile(intpoint)throwsException

FileWriterfw=newFileWriter("

BufferedWriterbw=newBufferedWriter(fw);

bw.write(point+"

bw.flush();

bw.close();

fw.close();

//更新up.dat文件

publicvoidupdateUpFile()throwsException

Setenteries=map.entrySet();

Iteratoriter=enteries.iterator();

StringBufferbuffer=newStringBuffer();

while(iter.hasNext())

Map.Entryentry=(Map.Entry)iter.next();

Stringip=(String)entry.getKey();

StringuserInfo=(String)entry.getValue();

buffer.append(ip+"

+userInfo+"

+"

\n"

bw.write(newString(buffer));

publicvoidsetProperties(Propertiespop){

ClientImpl类:

import.Socket;

importcom.briup.util.impl.ConfigurationImpl;

importcom.briup.woss.client.Client;

publicclassClientImplimplementsClient{

publicvoidsend(Collection<

c)throwsException{

Socketclient=newSocket("

127.0.0.1"

9001);

ObjectOutputStreamobject=newObjectOutputStream(client.getOutputStream());

object.writeObject(c);

client端的Main类:

packagecom.briup.woss.client;

importjava.util.Collection;

importcom.briup.util.BackUP;

importcom.briup.util.Configuration;

importcom.briup.util.Logger;

importstaticcom.briup.util.impl.ConfigurationImpl.*;

publicclassMain{

publicstaticConfigurationconf=getConfiguration();

publicstaticvoidmain(String[]args){

Loggerlogger=null;

Gathergather=null;

BackUPbackup=null;

Clientclient=null;

con=null;

try{

logger=conf.getClientLogger();

logger.info("

客户端开始启动"

gather=conf.getGather();

准备采集"

longa=System.currentTimeMillis();

con=gather.gather();

System.out.println(System.currentTimeMillis()-a);

采集成功"

backup=conf.getBackup();

client=conf.getClient();

准备发送 

client.send(con);

发送成功!

}catch(Exceptione){

logger.error(e.getMessage());

准备备份"

//backup.load();

backup.store(con);

备份成功"

}catch(Exceptione1){

e1.printStackTrace();

logger.error(e1.getMessage());

logger.warn("

采集失败"

ServerImpl类:

packagecom.briup.woss.server.impl;

import.ServerSocket;

importcom.briup.woss.server.DBStore;

importcom.briup.woss.server.Server;

importcom.sun.org.apache.xml.internal.serialize.Printer;

publicclassServerImplimplementsServer{

publicvoidrevicer(DBStoredbstore)throwsException{

c=newArrayList<

ServerSocketserver=newServerSocket(9001);

Socketsocket=server.accept();

ObjectInputStreamobject=newObjectInputStream(socket.getInputStream());

c=(Collection)object.readObject();

for(BIDRbidr:

c)

System.out.println(bidr);

dbstore.saveToDB(c);

object.close();

socket.close();

server.close();

//TODOAuto-generatedmethodstub

DBStoreImpl类

importstaticmon.ConnectionFactory.*;

importjava.sql.DriverManager;

importjava.util.Properties;

importjava.sql.*;

publicclassDBStoreImplimplementsDBStore{

privatestaticConnectioncon;

con=getConnection();

publicvoidsaveToDB(Collection<

c)throwsException{

PreparedStatementpsmt=null;

CallableStatementstmt;

//设置为自动提交事物

con.setAutoCommit(false);

//插入到t_detail_x中

Stringsql="

insertintot_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());

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("

{calldaypro}"

stmt.execute();

//调用monthpro存储过程执行对t_month_x插入数据

{callmonthpro}"

stmt.close();

//调用yearpro存储过程执行对t_year_x插入数据

/*CallableStatementstmt3=con.prepareCall("

{callyearpro}"

stmt3.execute();

stmt3.close();

psmt.close();

con.close();

server端的Main类:

packagecom.briup.woss.server;

/**

*服务器端的程序入口

DBStoredbstore=null;

Serverserver=null;

Loggerlogger=null;

dbstore=conf.getDBStore();

server=conf.getServer();

logger=conf.getServerLogger();

服务端等待接收数据"

server.revicer(dbstore);

服务端接收数据成功"

服务端接收数据失败"

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 其它课程

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1