在 ResultSet 中搜索特定值方法?
是否有一个 ResultSet 方法可以用来搜索 ResultSet 并检查它是否具有特定的值/元素?
类似于 ArrayList.contains()
方法。
如果没有,您不需要输入搜索方法,我会创建一个:)
提前致谢。
Is there a ResultSet method that I can use that would search through a ResultSet and check whether it has the specific value/element?
Similar to ArrayList.contains()
method.
If there isn't, you don't need to type up a search method, I'll make one :)
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在 Java 端进行搜索。这不必要地缓慢且占用内存。您基本上接管了数据库设计的工作。只需让数据库完成其设计目的即可:借助 SQL 语言功能准确选择并返回您想要的数据。
开始学习 SQL
WHERE
子句。例如,要检查用户名/密码是否匹配,请执行以下操作:Don't do the search in Java side. That's unnecessarily slow and memory hogging. You're basically taking over the job the DB is designed for. Just let the DB do the job it is designed for: selecting and returning exactly the data you want with help of the SQL language powers.
Start learning the SQL
WHERE
clause. For example, to check if an username/password mathes, do:假设您指的是 SQL ResultSet,答案是否定的,您必须编写一个。 JDBC 驱动程序通常不会一次检索所有行(如果查询返回 100 万行怎么办)。您必须自己阅读这些行并过滤它们。
Assuming you mean a SQL ResultSet, the answer is no, you have to write one. The JDBC driver usually won't retrieve all the rows at once (what if the query returned 1 million rows). You will have to read the rows and filter them yourself.