如何在like语句查询中设置占位符
我正在使用 SQL 创建一个 PreparedStatement
,它有一个 like
语句,并且我使用 setString()
方法设置占位符,但它确实如此不给出任何错误或获取任何记录。当我通过在类似语句中设置参数来直接在数据库运行查询时,我会得到结果,所以我认为可能有其他方法可以将占位符放入sql中,我正在这样做:
select name from employee where name like ?
我也尝试过:
select name from employee where name like (?)
并使用<设置参数code>setString() 方法,但我没有得到任何结果。
请帮忙看看有什么问题
I am creating a PreparedStatement
with SQL which have a like
statement, and I am setting the placeholders using setString()
, method, but it does not give any error or fetch any records. When I run the query direct at database by setting arguments in like statements then I get results, so I think there may be any other way to put place holders in sql, I am doing like below:
select name from employee where name like ?
I also tried:
select name from employee where name like (?)
and set parameters using setString()
method but I did not get any results.
Please help what is wrong in it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自 API 的示例:
您可以在以下位置查看更多信息: http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html
this is an example from API:
you can see more in : http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html
这是您最初使用它的方式。如果您需要另一篇文章来解释这一点,请参阅:
无法在 JDBCPreparedStatement 中使用 LIKE 查询?
It is the way by which you used it first. If you need another post which explains this, please see:
Cannot use a LIKE query in a JDBC PreparedStatement?