Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 11-06-2008, 11:03 AM Update query
Junior Talker

Posts: 3
Trades: 0
So i have a JTable displaying my search results. It has three columns, Nationality, First_Name and Last_Name, and 9 rows of data. Now i have decided for the sake of simplicaty till i get used to this, when the user clicks the update button, the new table model will just replcae everything in the database, so no need for any model listeners or hash codes, lol, etc.
So this is how it should be:

JTable displaying
9 rows of data

User edits this JTable

New table model sent
to database and replaces
table with the old data

So i have started the statement
Code:
String sql = "UPDATE tblCompetitor " +"SET Nationality = ?, First_Name = ?, Last_Name = ? " +"WHERE roundType2 = ? " +"AND eveType2 = ?";


This is mainly related to java which is why the sql statement looks different. And i know i shouldnt be using parameters but java allows you to do this which is why i have the ? What i really need to know is whether i am doing the format of the update correctly. If you had a table in your database, with 3 columns and 9 rows, and you wanted to update it completely with a whole new set of 9 rows, how would you perform this using the update statement?
cheers
nick2price is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2008, 01:45 PM Re: Update query
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
you will have to perform 9 UPDATE queries, one for each records, but yea the syntax is correct.

PHP Code:
UPDATE myTable SET field1='value1'field2='value2' WHERE field1='condition1' 
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 11-06-2008, 02:03 PM Re: Update query
Junior Talker

Posts: 3
Trades: 0
Does the WHERE clause have to be on field 1? My WHERE is done on a different condition. When i run this query in my database, it ask me to enter only 1 value for the SET, And 2 for event name and round type, but it doesnt append any rows.
nick2price is offline
Reply With Quote
View Public Profile
 
Old 11-06-2008, 02:10 PM Re: Update query
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by nick2price View Post
If you had a table in your database, with 3 columns and 9 rows, and you wanted to update it completely with a whole new set of 9 rows, how would you perform this using the update statement?
cheers
All update statements internally delete the old row and put a new one in its place. You could explicitly model that as a delete and then an insert command within a single transaction, but why?

Stoot98 brings up a more relevant concern. Either you need to fire off an individual update command on a row per row bases, identifying the specific row you'd like to update (ideally by PK) with the specific new values, or find a way to make this work with set theory.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 11-06-2008, 02:29 PM Re: Update query
Junior Talker

Posts: 3
Trades: 0
Really it should be two tables which are updated, but i am unsure if you can do this. My table are as follows

Code:
tblMeet
Id (PK)
Meet_Name
 
tblEvent
Id(PK)
Event_Name
Meet_ID(FK)
 
tblRound
ID(PK)
Round_Number
 
tblCompetitor
ID(PK)
Nationality
First_Name
Last_Name
 
tblResults
Competitor_ID(FK)
Event_ID(FK)
Round_ID(FK)
Result
So you can see tblResults, has control over most of the foriegn keys. So now i want to change all rows in my tblCompetitor where Round_ID = 1 and Event_Name = 100M Run. I can do this insert one by one because i will just do it through a loop in java. So what would this update statement look like? Would it be simular to how i have done it because at the moment the way i have it will not work.
nick2price is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Update query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26762 seconds with 12 queries