File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in updating record

 
Arun Bansal
Greenhorn
Posts: 11
  • 0
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic