web开发中多条件数据库查询语句怎么写,条件可有可无

web开发中多条件数据库查询语句怎么写,条件可有可无,第1张

给你一个简单的吧

string strsql = string.Format(@"select M.*,U.NAM_STF from tableA M, tableB U where M.USERID= U.COD_STF_LOG(+) ")

if (machineId.Trim() != "")

{

strsql = strsql + " and M.MACHINESN='" + machineId + "'"

}

if (employeeId.Trim() != "")

{

strsql = strsql + " and M.USERID='" + employeeId + "'"

}

if (workType.Trim() != "")

{

strsql = strsql + " and M.WORKTYPE='" + workType + "'"

}

if (dept.Trim() != "")

{

strsql = strsql + " and M.SECTION='" + dept + "'"

}

希望你能看懂,拼接字符串的形式

祝你好运

1.参数传到后台,通过hibernate的hql语句写一个普通的模糊查询就可以了,hql基本无法优化,只能加索引。

2.用jdbc或者mybatis。

3.配置文件应该是jdbc.properties吧?一般不需要,因为jdbc.properties里一般只写driver 、url、username和password,顶多还有一些连接池相关的配置。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6816625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存