Dave Tolls wrote:What is supposed to happen when a publisher is successfully retrieved?
Why can that not happen when a new publisher is added?
Dave Tolls wrote:I don't think you understood what I was getting at.
Person enters ISBN.
Code looks up Publisher.
What happens with the returned Publisher data (if it exists)?
Why can you not get the code to do whatever that is when a new Publisher is added?
the returned publisher is displayed
as for getting the code to do it that is what i am trying to do save asking the user to re-enter the isbn
it just seems that the data in mysql is not there at that moment and it is shortly after and it is this issue that i am trying to overcome, as for your suggestion that is what happens already if exsits display it if not ask the user for the name of the publisher and then add it to the database but it will not display it till it has restarted the mysql query but as you can see i have tried to do that in the back ground without success
In other words, I don't see any need to go back to the user to ask them to re-enter the ISBN.
You already have it after all.
Dave Tolls wrote:OK, then show us the code that handles the event that does the searching.
I would expect that to look like my Pseudo code (barring the entering of the ISBN).
Dave Tolls wrote:Not sure what 'publisher' is (as in class), but:
At this point you know the new name (from the if statement).
Why not, instead of using a new variable (pbname) use the existing one (pubname)?
That way you know the name you want to display.
There are formatting/structural issues with that code, by the way.
For example don't do:
The former version is prone to errors.
You also need to close off your Connection/Statement/ResultSets.
These should be handled using a try-with-resources. That will give you enough to Google.
Finally the query itself. i would expect a search on an ID to return 1 or zero rows, as the ID ought to be a primary key, and so unique.
So, rather than 'while (rs.next())' it ought to be 'if (rs.next())'. There's also no need for the DISTINCT either, and you should only pull back columns you need, not just use '*'.
And the PreparedStatement is incorrect as you are not binding the variable pubID at all.
(Note the above may not be entirely correct, since I guessed at the name of the column, and there could well be a typo elsewhere)