aspose file tools*
The moose likes JDBC and the fly likes Problem in updating record Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in updating record" Watch "Problem in updating record" New topic
Author

Problem in updating record

Arun Bansal
Greenhorn

Joined: Jun 01, 2010
Posts: 11
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in updating record