• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing the value from a variable to mysql

 
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem I am having is substituting the value in the update statement to that of the variable the is supplied in the parenthesis or even the set up within the method e.g.
int zxc=9;
I have tried all variations I can think of enclosing the variable escape \\ “ “ etc none of which work
When using
String query = "update books set quantity ='\"zxc\"' where isbn13 =" + isbn;
I get the following error report
java.sql.SQLException: Incorrect integer value: '"zxc"' for column 'quantity' at row 55492
the column in the books table is set to integer and is 10 wide and the values produced in the app numbers 0 through 40 only so should be sufficient
any ideal where the problem lies

 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to know you should use a PreparedStatement but you are using them wrongly. Take a look at http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html .
 
peter m hayward
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:You seem to know you should use a PreparedStatement but you are using them wrongly. Take a look at http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html .


Hi followed the link and try to adapt it to suit me needs here what i have so far


the reported error being
MySQL server version for the right syntax to use near '= 0 where = '9780708881422'' at line 1
at least i can now see the two parts of the data so if you could expand upon the tutorial and tell what i am doing wrong in order to correct it
thanks
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not the tutorial's problem, it's your SQL syntax which is wrong. Look more carefully at the error message -- there's something missing.
 
peter m hayward
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:It's not the tutorial's problem, it's your SQL syntax which is wrong. Look more carefully at the error message -- there's something missing.



Hi thanks for looking at my issue i did not mean the tutorial was wrong, and like you said i look over the mysql syntax and found out what was wrong so its fine now and if i had not followed the very good tutorial then i would not have solved the issue
thanks
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, you're on the right track now! Glad to hear it.

By the way almost all of the Oracle tutorials are worth reading (and following). As a general rule, when you start working on Topic X in Java then google the keywords "Java X tutorial" and chances are that will lead you to a tutorial about Topic X in Java. There may be others but I recommend the Oracle tutorials over the others.
 
peter m hayward
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Great, you're on the right track now! Glad to hear it.

By the way almost all of the Oracle tutorials are worth reading (and following). As a general rule, when you start working on Topic X in Java then google the keywords "Java X tutorial" and chances are that will lead you to a tutorial about Topic X in Java. There may be others but I recommend the Oracle tutorials over the others.



Hi Paul This something I have not thought of and will take up in the future thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic