zoukankan      html  css  js  c++  java
  • 团队个人冲刺day08

    今天实现了对数据库中新闻文本的读取

    public class DBUtil {
    private static String url = "jdbc:mysql://localhost:3306/xinwen?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
    private static String user = "root";
    private static String password = "0408";
    private static String jdbcName="com.mysql.jdbc.Driver";
    private Connection con=null;
    public static Connection getConnection() {
    Connection con=null;
    try {
    Class.forName(jdbcName);
    con=DriverManager.getConnection(url, user, password);
    //System.out.println("数据库连接成功");
    } catch (Exception e) {
    // TODO Auto-generated catch block
    //System.out.println("数据库连接失败");
    e.printStackTrace();
    }
    try {
    con = DriverManager.getConnection(url,user,password);
    System.out.println("连接成功");


    } catch (SQLException e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    return con;
    }
    public static void main(String[] args)throws SQLException {
    Bean bean = new Bean();
    Connection conn = getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql ="select content from xilang2";
    pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    rs = pstmt.executeQuery();
    System.out.println(getConnection());
    String content;
    rs.last();// 移动到最后
    int n=rs.getRow();
    System.out.println(rs.getRow());// 获得结果集长度
    rs.beforeFirst();
    String[] data=new String[n];
    int j=0;
    while(rs.next()){
    data[j]=rs.getString("content");
    System.out.println(data[j]);
    j++;
    }
    Connection conn2 = getConnection();
    Statement pstmt2 = null;
    pstmt2=conn.createStatement();
    for(int i=0;i<data.length;i++) {
    content = data[i];
    System.out.println(content);
    String type=BayesClassifier.getResult(content);
    System.out.println(type);
    String sql2="update xilang2 set type='"+type+"' where content='"+content+"'";
    pstmt2.execute(sql2);
    }
    /*try {
    while(rs.next())
    {
    String contant = rs.getString("contant");
    System.out.println(contant);
    }
    }catch(SQLException e){
    e.printStackTrace();
    }*/

    // return con;

    }
    public static void close(Connection con) {
    if(con!=null)
    try {
    con.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    public static void close(PreparedStatement state, Connection conn) {
    if(state!=null) {
    try {
    state.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(conn!=null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    public static void close(ResultSet rs, Statement state, Connection conn) {
    if(rs!=null) {
    try {
    rs.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(state!=null) {
    try {
    state.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(conn!=null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    }

  • 相关阅读:
    计算机基础数据结构讲解第九篇-顺序队列
    计算机基础数据结构讲解第八篇-栈
    计算机基础数据结构讲解第七篇-链表操作
    计算机基础数据结构讲解第六篇-顺序表操作
    计算机基础数据结构讲解第五篇-顺序表
    计算机基础数据结构讲解第三篇-B树和B+树
    计算机基础数据结构讲解第二篇-散列查找
    MLHPC 2018 | Aluminum: An Asynchronous, GPU-Aware Communication Library Optimized for Large-Scale Training of Deep Neural Networks on HPC Systems
    MXNet源码分析 | KVStore进程间通信
    链表类问题
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14910163.html
Copyright © 2011-2022 走看看