码迷,mamicode.com
首页 > 其他好文 > 详细

爬出系统-生成标签

时间:2017-03-23 01:04:41      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:rom   replace   main   插入   ext   成功   tac   getc   apach   

package com.open1111.tag;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.open1111.util.DbUtil;

public class TagMain {

private static Logger logger=Logger.getLogger(TagMain.class);

public static void main(String[] args) {
logger.info("生成Tag开始");
DbUtil dbUtil=new DbUtil();
Connection con=null;
try {
con=dbUtil.getCon();
logger.info("创建数据库连接成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.info("创建数据库连接失败");
}
String sql="select * from t_jar where tagState=0";
try {
PreparedStatement pstmt=con.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
String id=rs.getString("uuid");
String name=rs.getString("name");
String names[]=name.replaceAll(".jar", "").split("-");
for(String n:names){
if(n.contains(".")){
continue;
}
String sql2="select * from t_tag where name=?";
PreparedStatement pstmt2=con.prepareStatement(sql2);
pstmt2.setString(1, n);
ResultSet rs2=pstmt2.executeQuery();
if(!rs2.next()){ // 假如不存在 我们插入tag
String sql3="insert into t_tag values(null,?)";
PreparedStatement pstmt3=con.prepareStatement(sql3);
pstmt3.setString(1, n);
pstmt3.executeUpdate();
logger.info("插入标签:"+n);
}
}
// 更新数据库tagState状态字段 改成1
String sql4="update t_jar set tagState=1 where uuid=‘"+id+"‘";
PreparedStatement pstmt4=con.prepareStatement(sql4);
pstmt4.executeUpdate();
}
} catch (SQLException e) {
logger.error("SQLException",e);
}
try {
dbUtil.closeCon(con);
} catch (Exception e) {
logger.error("Exception",e);
}
logger.info("生成Tag结束");
}
}

爬出系统-生成标签

标签:rom   replace   main   插入   ext   成功   tac   getc   apach   

原文地址:http://www.cnblogs.com/csy666/p/6602499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!