Find a ResultSet for a specific value method?

Is there a ResultSet method that I can use that will look through the ResultSet and check if it has a specific value / element?

Like the ArrayList.contains() method.

If this does not happen, you do not need to enter a search method, I will do the following :)

Thanks in advance.

+4
source share
2 answers

Do not search on the Java side. It is unnecessarily slow and memorizing memory. You basically do the work for which the database is intended. Just let the database complete the task designed to: select and return exactly the data that you want using SQL permissions.

Start exploring the SQL WHERE . For example, to verify that the username / password matches, follow these steps:

 connection = database.getConnection(); preparedStatement = connection.prepareStatement("SELECT * FROM user WHERE username=? AND password=md5(?)"); preparedStatement.setString(1, username); preparedStatement.setString(2, password); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { // Match found! } else { // No match! } 
+5
source

Assuming you mean SQL ResultSet, the answer is no, you should write one. The JDBC driver will usually not retrieve all rows at once (what if the query returned 1 million rows). You will have to read the lines and filter them yourself.

+2
source

Source: https://habr.com/ru/post/1335924/


All Articles