zoukankan      html  css  js  c++  java
  • android 学习

    Dao层

    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"));
                    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;
        }
    }
  • 相关阅读:
    树、森林和二叉树的转换
    弱校ACM奋斗史
    安徽科技学院2016-2017-1学期2013信息与计算科学12班期末测试_题解
    安徽省2016“京胜杯”程序设计大赛_K_纸上谈兵
    安徽省2016“京胜杯”程序设计大赛_J_YZK的大别墅
    安徽省2016“京胜杯”程序设计大赛_I_恶魔A+B
    安徽省2016“京胜杯”程序设计大赛_H_单身晚会
    安徽省2016“京胜杯”程序设计大赛_G_木条染色
    安徽省2016“京胜杯”程序设计大赛_F_吃在工大
    LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。
  • 原文地址:https://www.cnblogs.com/Nojava/p/14908861.html
Copyright © 2011-2022 走看看