• jdbc模糊查询、分页查询、联合查询


    ---------------模糊查询------------------------

    正常的jdbc查询的sql语句,类似这样,

    "select * from balance where username = ?"

    pstat.setString(1,username)//通过这个方法告诉数据库,类型(如果是字符串就'') 和 值 底层帮我们拼接成 select * from balance where username= 'xxx';



    jdbc模糊查询 like %% , _
    方式一:sql语句不变,拼接值,把%%,在赋值语句那里处理
    "select * from balance where username like ?"
    pstat.setString(1,"%"+username+"%");//把"%"+username+"%"这个整体当做一个字符串值,%username%,setString所有添加''
    底层拼接好的就是 "select * from balance where username like '%关键字%'"

    方式二:sql语句修改,其它不变

    "select * from balance where username like "%" ? "%" "

    这里把%用"包起来,不过注意要用转义符

    ------------分页查询------------------------

    -----------------联合查询-----------------------

  • 相关阅读:
    169. Majority Element
    283. Move Zeroes
    1331. Rank Transform of an Array
    566. Reshape the Matrix
    985. Sum of Even Numbers After Queries
    1185. Day of the Week
    867. Transpose Matrix
    1217. Play with Chips
    766. Toeplitz Matrix
    1413. Minimum Value to Get Positive Step by Step Sum
  • 原文地址:https://www.cnblogs.com/hebiao/p/14518613.html
Copyright © 2020-2023  润新知