This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem in updating record

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic