0

I am trying to update the SSN for a customer by searching for them based on the old SSN then updating it. What am I missing? This will not return a result even though i know i have matches for ssNum in the database. Thanks.

String query = "UPDATE Customers SET ss_num = ('" + updateSsn
                + "') WHERE ss_num = ('" + ssNum + "')";
jmj
  • 237,923
  • 42
  • 401
  • 438
Gluons
  • 19
  • 5

2 Answers2

3

That type of query is unsafe (vulnerable to SQL injection). Write your query as follows and use PreparedStatement:

String query = "UPDATE Customers SET ss_num = ? WHERE ss_num = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, updateSsn);
ps.setString(2, ssnNum);
Community
  • 1
  • 1
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
1

you need to use executeUpdate() method, which doesn't return ResultSet, but it will return numberOfRowsUpdated

Use PreparedStatement instead

jmj
  • 237,923
  • 42
  • 401
  • 438