Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Db Update Question

 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi FOlks,
More than a JDBC q, this is really a SQL question. I hope someone out there can help me..
I have a database table, say customers, with cus_number, cus_name, cus_birthdate and cus_ssn
Now, i get a flat file with the the cus_number and cus_ssn on it. Have a java program that reads it, and then I need to populate the ssn field if the cus_number is already in the database.
Also need to be able to ignore if a cus_number is not found. FYI, i'm using mysql on winnt and I already have the JDBC drivers installed and everything and I'm able to access the db from the java program..
What i really need is help in formatting the update statement to update only one field of the db without affecting the others AND on how to catch a not-found cus_number
Thanks !!
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about something like:
<code>
String query = "UPDATE Customers SET cus_ssn = " + (your 1st java variable as read in from file) + " WHERE cus_number = " + (your 2nd java variable as read in from file);
</code>
If the customer number is not already in the database, no update will take place. If it is, only the cus_ssn field will be updated.
Easy as that.

------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic