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

    }

  • 相关阅读:
    [CTF]zip伪加密
    Node.js躬行记(5)——定时任务的调试
    不一样的资产安全 3D 可视化平台
    冬季里有温度的 3D 可视化智慧供热系统
    公路项目建设可视化进度管理
    ElementUI时间选择控件提交的时间为UTC时间
    Orcal创建触发器
    Orcal常用查询实例集合
    代码优化风格分享
    查某月的天数
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14910163.html
Copyright © 2011-2022 走看看