Rosie Fairfield wrote:Roel,
Yes that's right.
Based on your code it seems you have a resultset which is populated with the results of a
SELECT * FROM Book query. And you are traversing this resultset to look for a title entered by the user. This is a very poor approach. First of all, if you have a million books in your Book table, you'll have to iterate over 815632 books to display book number 815633 and that's pretty slow. What if several books have the same title? You risk resource leaks if you don't close the resultset. And finally, it seems the resultset stys available during the complete execution of the application, even when it's not used (and the user goes out for a 1h lunch). So if your database allows only 10 active connections at any given time, user 11 can only run the application if one of the 1st 10 users closes the application (and you properly close the used resultsets, statements and connections).
Why don't you implement this method as follows:
- user enters title to search books
- the query
SELECT * FROM Book WHERE title = ? is executed (? is replaced with the title entered by the user)
- if the resultset is not empty, these books are displayed (because title can result in more than 1 search result, unless it's a primary key)
- if the resultset is empty, an error message is shown to the user
This method implementation makes much more sense and doesn't have any of the aforementioned issues of the current implementation.
Hope it helps!
Kind regards,
Roel