Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

mysql control

 
Ranch Hand
Posts: 147
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a method that takes the 13 digit number (isbn) that is entered into a textfield within this method the is a process to retrieve the publisher, now when the publisher exists in the database everything is fine, however if it is not the a joption box is triggered to ask for the name of the publisher, having supplied this and clicking the ok on the option box the new publisher is then added to the database, however it is not available to the original method until i clear everything and re-enter the isbn thus restarting the method i have tried a few different ways to over come this issue but it seems i am once again out of my depth so if you can explain what i need to know or look at to correct this issue that would be great

the code above works in as far as it adds the new publisher to mysql it then call restart but this seems not to have the desired effect even thou if i do it manually it dose works the code for this being


so the work flow is as follow scan isbn in to textfield a method that connects to mysql retrieves the data, a method is called that finds the publisher code from the isbn, this is then used to retrieve the publisher from mysql if it exists, if not a option box is displayed asking for the publisher name this is then passed to a method that puts this new publisher along with the publisher code into mysql at this point if i start over the new publisher is available and gets displayed, so i tried to create a method that would automatically start over but this does not work
 
Rancher
Posts: 4174
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is supposed to happen when a publisher is successfully retrieved?

Why can that not happen when a new publisher is added?
 
peter m hayward
Ranch Hand
Posts: 147
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?



normally a publisher exists in the database and gets displayed in a textfield  E.G. the publisher code for New English library = 450 which is part of the isbn = 978-0-450-53737-0
now when the isbn 9781864761009 is entered into the textfield  the method produces a publisher code = 86476 from the isbn =978-1-86476-100-8
the number 86476 is then used to find the publisher in the database but on this occasion it does not exist so a joption box gets displayed so the name of this publisher can be added along with its id =86476 into the database now i require it to be displayed in the publisher textfield as if it it was already in the database however this does not happen until i clear all textfields  and re-enter the isbn into the data input textfield. so i thought i would create a method that preserved the isbn then cleared everything then re-entered it and trigger the process as if i had done it manually my code to do this being
 
Dave Tolls
Rancher
Posts: 4174
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you understood what I was getting at.

Person enters ISBN.
Code looks up Publisher.
Then what?

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?

eg.

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.
 
peter m hayward
Ranch Hand
Posts: 147
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:I don't think you understood what I was getting at.

Person enters ISBN.
Code looks up Publisher.
Then what?

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?
Hi Dave


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



eg.

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
Rancher
Posts: 4174
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
peter m hayward
Ranch Hand
Posts: 147
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Rancher
Posts: 4174
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

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)
 
peter m hayward
Ranch Hand
Posts: 147
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to think about

pete


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:

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)

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!