• 每日随笔


    今天研究了模糊查询的相关语句,其中有and和or两种模式

    public List<Bean> searchByName(String str) throws SQLException{//查询条件方法
    String sql="select * from person where(name like '%"+str+"%')";
    Connection conn=DBUtil.getConnection();
    Statement st=null;
    PreparedStatement pt = conn.prepareStatement(sql);
    List<Bean> search=new ArrayList<>();
    ResultSet rs=null;
    Bean bean=null;
    try {
    pt=conn.prepareStatement(sql);
    rs=pt.executeQuery();
    while(rs.next()) {
    int id=rs.getInt("id");
    String hubie = rs.getString("hubie");
    String livetype = rs.getString("livetype");
    int area=rs.getInt("area");
    int roomnum=rs.getInt("roomnum");
    String name = rs.getString("name");
    String idcard=rs.getString("idcard");
    String sex = rs.getString("sex");
    String nation = rs.getString("nation");
    String education = rs.getString("education");
    bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education);
    search.add(bean);
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    finally {
    DBUtil.close(rs, st, conn);
    }
    return search;
    }

  • 相关阅读:
    promise请求数据(all方法)
    右键的点击事件
    微信小程序的接口调用封装
    微信小程序HTTP接口请求封装
    微信小程序得路由跳转
    管理系统得操作与解决思路
    HTTP协议
    动态语言概述
    AsynclAwait
    三种跨域解决方案
  • 原文地址:https://www.cnblogs.com/buxiang-Christina/p/14158987.html
Copyright © 2020-2023  润新知