• 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.明天目标

  • 相关阅读:
    ora04063:view view_test has errors
    toad for oracle中登入界面Connect using框和TNSNames Editor框的显示状态
    格式化时间,转为中文
    一些简单有用的方法合集
    C#加密解密
    计算员工有效工作时间(C#版)
    计算员工有效工作时间(sql版)
    JavaScript 语言基础知识点总结(思维导图)
    正则表达式
    C#中请不要混淆引用类型和ref引用传参
  • 原文地址:https://www.cnblogs.com/qiangini/p/14909678.html
Copyright © 2020-2023  润新知