网页的设计流程是怎样的,怎么做外贸网站seo,吴桥县做网站价格,南京最大网站建设公司大家好#xff0c;我是雄雄#xff0c;欢迎关注微信公众号#xff1a;雄雄的小课堂 前言
现在是#xff1a;2022年4月20日13:33:23
以前是怎么都没想到#xff0c;我需要在服务器的nohup文件中找记录#xff0c;然后往数据库里面更新。具体因为啥不提了#xff0c;说多… 大家好我是雄雄欢迎关注微信公众号雄雄的小课堂 前言
现在是2022年4月20日13:33:23
以前是怎么都没想到我需要在服务器的nohup文件中找记录然后往数据库里面更新。具体因为啥不提了说多了都是愧啊~今天主要是分享一个java解析nohup文件提取关注的信息然后添加到数据库中。
实现思路
刚开始我是直接将nohup文件中的信息手动复制出来然后写了个insert的sql语句一条一条的往里面添加结果发现有上千条这么干不睡觉都加不进去多少于是想到了找小杨和小于帮帮忙无奈有点复杂光给他两讲怎么加讲了半天还不能保证他两会了数据能加对。。。。。
后来想了个办法将nohup文件先转换成txt文件然后解析txt文件根据关键字提取关键信息拿到之后截取成固定字符串通过jdbc的方式添加在数据库中。
将nohup文件的后缀改成txt观察自己关注的数据的规律尤其是前后有什么可以标识的看了看可以根据Parameters这个来解析。 因为很不规律所以有单独查找了下(Timestamp)截取成一个字符串本来想着按照逗号来将这个字符串中所有需要的信息截取到依次添加到数据库中结果发现有个字段是介绍里面的值也有逗号有中文的逗号也有因为的逗号这种方法看来行不通。想办法查找Stirng全文替换成~,然后按照~查找最后在截取终于可行了。
实现代码
1.按照Parameters解析txt文件 package com.ruoyi.web.controller.util;import com.ruoyi.system.domain.EquipmentRZ;import java.io.File;import java.io.FileNotFoundException;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Scanner;/*** author: muxiongxiong* date: 2022年04月19日 上午 11:05* 公众号雄雄的小课堂* 博客https://blog.csdn.net/qq_34137397* 个人站http://www.穆雄雄.com* 个人站http://www.muxiongxiong.cn* Description: 解析txt文件获取里面的数据* 最初解析的是nohup文件现在改为解析txt文件* 将txt文件里面的内容解析成对象添加到认证器材表里去*/public class ParseTXTFileUtils {public void parseTxt(){File file new File(D:\\test3.txt);SimpleDateFormat simpleDateFormat new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);if (!file.exists()) {System.out.println(节点基本信息文件未找到);}Scanner s null;try {s new Scanner(file);} catch (FileNotFoundException e) {e.printStackTrace();}while (true) {//文档中的内容String danci s.next();if (Parameters:.equals(danci)) {//开始留存需要的数据.String jixu ;int count 0;while (true) {EquipmentRZ equipmentRZ new EquipmentRZ();String danci2 s.next();jixu danci2;if (danci2.indexOf(Timestamp) ! -1) {String sheng s.next();String shi s.next();String qu s.next();String renzheng s.next();String tupian s.next();String jieshuriqi s.next();jixu sheng shi qu renzheng tupian jieshuriqi;//System.out.println(jixujixu);//按照逗号分割String[] split jixu.split(~,);//获取到的数据try {equipmentRZ.setId(Integer.parseInt(split[0]));equipmentRZ.setName(split[1]);equipmentRZ.setXinghao(split[2]);equipmentRZ.setJianjie(split[3]);equipmentRZ.setZhuangtai(split[4]);equipmentRZ.setGongsi1(split[5]);equipmentRZ.setGongsi2(split[6]);equipmentRZ.setRealName(split[7]);equipmentRZ.setLeixing(split[8]);equipmentRZ.setGongsi3(split[9]);//2016-11-3011:35:08.0(Timestamp),天津市String shijian split[10];//按照逗号分割String[] split1 shijian.split(,);//截取最后的(Timestamp)int index split1[0].lastIndexOf(();String kaishishijian split1[0].substring(0, index);//第9位后面加上空格StringBuffer sb new StringBuffer(kaishishijian);sb.insert(10, );equipmentRZ.setBeginDate(simpleDateFormat.parse(sb.toString()));equipmentRZ.setSheng(split1[1]);equipmentRZ.setShi(split[11]);equipmentRZ.setJiedao(split[12]);equipmentRZ.setRenzheng(split[13]);equipmentRZ.setTupian(split[14]);String jieshu split[15] 00:00:00;equipmentRZ.setEndDate(simpleDateFormat.parse(jieshu));//System.out.println(equipmentRZ);} catch (ParseException e) {e.printStackTrace();}//调佣添加的方法 将数据添加到数据库//已经执行完毕 2022年4月19日11:08:54/* ZhiXingMysql zhiXingMysql new ZhiXingMysql();zhiXingMysql.saveEquipmentRZ(equipmentRZ);*/break;}}}}}}
2.由于字段太多了所以封装了个实体类字段如下 /*** author: muxiongxiong* date: 2022年04月19日 0:25* 公众号雄雄的小课堂* 博客https://blog.csdn.net/qq_34137397* 个人站http://www.穆雄雄.com* 个人站http://www.muxiongxiong.cn* Description: 类的描述*/
public class EquipmentRZ {private Integer id;private String name;private String xinghao;private String jianjie;private String zhuangtai;private String gongsi1;private String gongsi2;private String gongsi3;private String realName;private String leixing;private Date beginDate;private String sheng;private String shi;private String jiedao;private String tupian;private String renzheng;private Date endDate;}3.jdbc添加到数据库中的方法 public void saveEquipmentRZ(EquipmentRZ equipmentRZ) {int success 0,err0;String sql INSERT INTO sys_rzequipment ( equipment_id,equipment_name, equipment_model, equipment_introduction,equipment_status, production_name, maintenance_name, installation_company_name,maintenance_people, equipment_type, installation_date, installation_province, installation_city, installation_address, equipment_img_url, create_time,date_come_from ) \n VALUES(?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?);Connection connection null;PreparedStatement pStatement null;try {connection getConnection();pStatement connection.prepareStatement(sql);pStatement.setInt(1, equipmentRZ.getId());pStatement.setString(2, equipmentRZ.getName());pStatement.setString(3, equipmentRZ.getXinghao());pStatement.setString(4, equipmentRZ.getJianjie());pStatement.setString(5, equipmentRZ.getZhuangtai());pStatement.setString(6, equipmentRZ.getGongsi1());pStatement.setString(7, equipmentRZ.getGongsi2());pStatement.setString(8, equipmentRZ.getGongsi3());pStatement.setString(9, equipmentRZ.getRealName());pStatement.setString(10, equipmentRZ.getLeixing());pStatement.setObject(11, equipmentRZ.getBeginDate());pStatement.setString(12, equipmentRZ.getSheng());pStatement.setString(13, equipmentRZ.getShi());pStatement.setString(14, equipmentRZ.getJiedao());pStatement.setString(15, equipmentRZ.getTupian());pStatement.setObject(16, equipmentRZ.getEndDate());pStatement.setString(17, equipmentRZ.getRenzheng());int count pStatement.executeUpdate();if(count0){success;System.out.println(成功:successequipmentRZ.getId());}else{err;System.out.println(失败:errequipmentRZ.getId());}} catch (Exception e) {e.printStackTrace();} finally {closePreparedStatement(pStatement);closeConnection(connection);}}
最后运行main方法就可以了。、
注意事项
为了保险起见刚开始测试的时候测试添加的数据尽量的少点儿也就是将txt重新复制出来一份只留几条记录执行一遍main方法观察一下数据库中的数据是否正确。执行的过程中可能会遇到错误因为Parameters可能在登录操作的时候也会出现所以遇到不是添加的sql的话也会报错的只需要将原来执行过的删掉不规则的Parameters数据在txt文件中删掉继续执行即可。