2021/6/3

1.今日收获内容

package com.lunwen.Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.lunwen.bean.Select;
import com.lunwen.bean.data;
import com.lunwen.bean.lunwen;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.*;
import com.mysql.jdbc.Statement;
import com.lunwen.DBUtil.DBUtil;


public class ShowDao {
    public List<lunwen> select(){
        Connection conn = DBUtil.getConn(); //连接数据库
        List<lunwen> list = new ArrayList<lunwen>();
        try {
            String sql="select * from lunwen";
            Statement pstmt = (Statement) conn.createStatement();
            ResultSet rs = (ResultSet) pstmt.executeQuery(sql);
            while(rs.next()) {
                lunwen lunwen=new lunwen();
                lunwen.setTitle(rs.getString("title"));//这里title改成abstract可以实现  摘要   热词提取
                list.add(lunwen);
            }
            System.out.println("ShowDao Success!!");
            rs.close();
            pstmt.close();
            conn.close();

        }catch(SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<data> select1(String name){
        Connection conn = DBUtil.getConn(); //连接数据库
        List<data> list = new ArrayList<data>();
        try {
            String sql="select * from lunwen where keywords like '%"+name+"%'";//这里和上面一样(摘要)
            Statement pstmt = (Statement) conn.createStatement();
            ResultSet rs = (ResultSet) pstmt.executeQuery(sql);
            while(rs.next()) {
                data data=new data();
                data.setAbs(rs.getString("abs"));
                data.setTitle(rs.getString("title"));
                data.setLink(rs.getString("link"));
                data.setKeyword(rs.getNString("keywords"));
                System.out.println(data.getTitle()+":"+data.getLink());
                list.add(data);
            }
            System.out.println("ShowDao select1 Success!!");
            rs.close();
            pstmt.close();
            conn.close();

        }catch(SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    
    public List<data> secletAll(Select s){
        Connection conn = DBUtil.getConn(); //连接数据库
        List<data> list = new ArrayList<data>();
        try {
            String sql="select * from lunwen where keywords like '%"+s.getKeywords()+"%' and link like '%"+s.getLink()+"%' and title like'%"+s.getTitle()+"%'" ;//这里和上面一样(摘要)
            Statement pstmt = (Statement) conn.createStatement();
            ResultSet rs = (ResultSet) pstmt.executeQuery(sql);
            while(rs.next()) {
                data data=new data();
                data.setAbs(rs.getString("abs"));
                data.setTitle(rs.getString("title"));
                data.setLink(rs.getString("link"));
                data.setKeyword(rs.getNString("keywords"));
                System.out.println(data.getTitle()+":"+data.getLink());
                list.add(data);
            }
            System.out.println("ShowDao select1 Success!!");
            rs.close();
            pstmt.close();
            conn.close();

        }catch(SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    
    public List<data> deleteAll(String name){
        Connection conn = DBUtil.getConn(); //连接数据库
        List<data> list = new ArrayList<data>();
        try {
            String sql="delete  from lunwen where keywords ='"+name+"'";//这里和上面一样(摘要)
            Statement pstmt = (Statement) conn.createStatement();
            int count = pstmt.executeUpdate(sql); 
            if(count>0) {
            System.out.println("ShowDao deleteAll Success!!");
            }
            pstmt.close();
            conn.close();

        }catch(SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}

数据库链接
2.遇到的问题
链接失败,后来改正

3.明天目标

原文地址:https://www.cnblogs.com/qiangini/p/14909678.html