File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Problem in updating record" Watch "Problem in updating record" New topic

Problem in updating record

Arun Bansal

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.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

When you're calling 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); 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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Problem in updating record
It's not a secret anymore!