Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Unreasonable error: Invalid operation at current cursor position.

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I use the following method to find and display the record of a book with a title either passed into
the method or input from JTextField textSearchTitle if the empty string is passed in.

In order to return the ResultSet back to the current record so I can scroll forwards and backwards properly,
I call searchAndDisplayRecord() passing it the title of the current book; see line 50.

When I did this I began to get an error: Invalid operation at current cursor position. and my navigation
buttons didn't work.

I fixed this with the recordsBooks.first() call on line 48.

My question is: since I call recordsBooks.first() on line 25 before I run the ResultSet to find the book,
why do I have to do it again on line 48? It doesn't make sense and feels unclean to me or like I'm
missing something.

Any ideas?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the purpose of this method? As I understand: user enters a title of a book, the code searches the database for that book. If found, that book is displayed in the gui. If not found, the displayed book prior to the search is shown. Correct?
 
Rosie Fairfield
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,

Yes that's right.
 
Master Rancher
Posts: 4665
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where exactly is that error being thrown?

Also, where does resultSet reside?

Is it possible it's being shared somehow and somewhere else in your code it is being reused?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic