详细解决方案
模糊查询时用到prepareStatement在SQL语句里的问号如何写
热度:3164 发布时间:2013-02-25 21:10:57
我用了prepareStatement(sql)来防止SQL注入问题,出入的SQL语句参数全部用?代替的,但是我有用到模糊查询不知道模糊查询的SQL语句的参数怎么用?取代。
我是这么写的,但是查不到结果,那位高手可以指点一下啊,先谢了:
select * from book_info where book_name like '%?%' and book_type like'%?%' and book_author like '%?%' and book_publisher like '%?%'
------解决方案--------------------------------------------------------
要+连接字符串
select * from book_info where book_name like '%'+?+'%' and book_type like'%'+?+'%' and book_author like '%'+?+'%' and book_publisher like '%'+?+'%'
------解决方案--------------------------------------------------------
select * from book_info where book_name like '%"+?+"%' and book_type like'"%+?+"%' and book_author like '%"+?+"%' and book_publisher like '%"+?+"%'
上面这样写就OK了
记得要多结贴!
------解决方案--------------------------------------------------------
相关解决方案
- PreparedStatement pstmt=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);oracle出现java.sql.SQLException: 不支持的特性的异常,什么原因
- prepareStatement 的有关问题
- ORACLE内char的参数处置(connection.prepareStatement)
- PrepareStatement(sql预处理类)
- statement、prepareStatement、callableStatement的运用
- prepareStatement.setString 有关问题求租
- prepareStatement (),该怎么解决
- ps = con.prepareStatement(FinalConstants.SELECT_USER+sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);该如何处理
- prepareStatement 有关问题 ,请高手 帮忙
- jdbc prepareStatement,该怎么处理
- pstmt=conn.prepareStatement(sql)空指针错误,求大神支招
- preparestatement 使用有关问题-着
- preStmt = conn.prepareStatement(sql);执行到这里就出错,为什么,该如何处理
- java.sql.Connection.prepareStatement(String sql)中sql的大小限制有关问题
- 黑马day10 预编译解决sql的流入攻击&PrepareStatement