如何拼接SQL条件
答案:6 悬赏:50
解决时间 2021-12-30 22:36
- 提问者网友:乱人心
- 2021-12-30 03:49
我记得是把查询条件封装到BEAN里面,然后再怎么办呀
最佳答案
- 二级知识专家网友:一只傻青衣
- 2021-12-30 04:10
and || or?
全部回答
- 1楼网友:夢想黑洞
- 2021-12-30 09:34
不会哦
- 2楼网友:湫止没有不同
- 2021-12-30 09:19
select * from (
select case when 条件1 then time1 when 条件2 then time2 when 条件3 then time3
else getdate() end as time from table) a where time ***
- 3楼网友:浪女动了心
- 2021-12-30 08:01
直接调用getsession()方法来执行 你拼的 sql语句啊。 就这样就好了
- 4楼网友:年轻没有失败
- 2021-12-30 06:28
我给你一种方法:
String sql="select * from 【table】where 1=1 ";
if(条件1){
sql+=" and name='king' "}
if(条件2){
sql+=" and password='123' "}
.....
.....
就这么拼下去
- 5楼网友:茫然不知崩溃
- 2021-12-30 05:41
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DbConnection.getInstance().getMnpConnection();
pst = conn.prepareStatement(“select id ,name from table where id=? and name=?”);//简单写个语句可能不好
// pst.setLong(1, p.getId());
pst.setTimestamp(1, new Timestamp(pushTimer.getTimer()));
pst.setLong(2, p.getPaperId());
pst.setInt(3, p.getIssueNo());
pst.executeUpdate();
ret = true;
给你复制了一点代码,一般我们在系统里都是这样写的,比较正规。你如果不是刚入门的话应该能看懂。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯