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 \"%\" ? \"%\" "

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

 

 

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

 

 

 

 

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

 

posted on 2021-03-11 16:08  刀锋93  阅读(207)  评论(0编辑  收藏  举报

导航