• 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

Problem in updating record

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends, i'm new one to java. i'm trying to update a table data by taking input from user at runtime but when i'm running my code it is accepting only one value and rest two it is showing wrong.
my code is below here. I'm using myeclipse and Mysql.




this is what happeing when i'm running this.


Table Structure

Any response is appriciated.
Thanks
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you're calling br.read() this will read one char. This will be the 2, which has an ASCII value of 50. This is why you're getting 50. It also explains why the place becomes 5; after reading the 2, the br.readLine() call after that returns the 5. The actual place you need to enter is skipped because of this.

Simply change the int str2 = (int) br.read(); line into this:

Also, you should check out PreparedStatement. Your code has a potential for SQL injection. If someone enters ';DELETE FROM test;UPDATE test SET name=' as the name, the query becomes this:
In other words: clear the names of all records, then delete all records, then try to update a non-existing record. With PreparedStatement this is prevented.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic