zoukankan      html  css  js  c++  java
  • 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.明天目标

  • 相关阅读:
    第二次
    第一次
    win下less自动编译脚本
    厦门攻略游记
    npm常用命令
    青岛旅行规划及玩后感
    kissynode run on windows解决方案,contextify nodejs windows solution
    win nodejs下 findit只返回第一个文件问题
    jetty自动添加path的问题
    微博输入框统计
  • 原文地址:https://www.cnblogs.com/qiangini/p/14909678.html
Copyright © 2011-2022 走看看