Updating Database Problem...

i want to be able to update individual contacts in my table but ive run into a problem: when i update 1 contact ALL contacts in the table get updated with the same info as the contact that i updated. i know where im going wrong and i need ur help to fix it :)

publicvoid updateContact(ContactPanel updatePanel){

try{

preparedStatement = connection.prepareStatement("update A set NAME = ?, NUMBER = ?, EMAIL = ?");

preparedStatement.setString(1, updatePanel.getName());

preparedStatement.setString(2, updatePanel.getNumber());

preparedStatement.setString(3, updatePanel.getEMail());

preparedStatement.executeUpdate();

}catch(SQLException ex){

ex.printStackTrace();

}

}

its this line of code thats causing the problem:

preparedStatement = connection.prepareStatement("update A set NAME = ?, NUMBER = ?, EMAIL = ?");

im updating the whole table and not just a single contact. any1 got ideas of how i could update a single contact? thnx :)

[1365 byte] By [Alex1989a] at [2007-11-27 5:49:26]
# 1
Your SQL should look like:UPDQATE A SET NAME = ?, NUMBER = ?, EMAIL = ? WHERE YOUR_ID_FIELD = ?
Hippolytea at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 2
aha thnx! im havin a problem at the moment, my id always stays at 1. never goes higher with the whole ++ thing
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 3
> aha thnx! im havin a problem at the moment, my id> always stays at 1. never goes higher with the whole> ++ thingWhat whole ++ thing would this be exactly?
cotton.ma at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 4
inside my "ContactPanel" class i have an int called "contactID" that gets incremented each time a contactpanel is created. now obviously each time i close the IDE contactID will be reset to 0 but thats beside the point at the moment. so how would i go about giving each contact their own
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 5
Every database I can think of has a way to generate identities. Why force yourself to do it?
Hippolytea at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 6
they can?...
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 7
> they can?... http://en.wikipedia.org/wiki/Surrogate_key
Hippolytea at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 8
i went through a lot of that wiki article but it didnt tell me how i can make 1. im using a derby database
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 9
> i went through a lot of that wiki article but it> didnt tell me how i can make 1. im using a derby> database http://db.apache.org/derby/docs/10.2/ref/rrefsqlj37836.html
cotton.ma at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 10

> > i went through a lot of that wiki article but it

> > didnt tell me how i can make 1. im using a derby

> > database

>

> http://db.apache.org/derby/docs/10.2/ref/rrefsqlj37836.html

That a good life lesson as well. The Wiki article was the general background,

but if you want specific information about product X, consider reading

the documentation for product X.

Hippolytea at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 11
is there a way to make an identity using "create table" instead of "execute command"?
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 12
Yes, you can create tables via the JDBC and SQL's "CREATE TABLE..." statement.Details of the various column types vary vendor to vendor, butthat's where you would indicate an AUTO_INCREMENT field, for example.Sorry, I don't know Derby.
Hippolytea at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 13
> is there a way to make an identity using "create> table" instead of "execute command"?The documentation link I gave you shows several example of create table so I don't really understand your confusion...
cotton.ma at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 14
i mean using a GUI to create a table so thats its not so confusing
Alex1989a at 2007-7-12 15:36:00 > top of Java-index,Java Essentials,Java Programming...
# 15
> i mean using a GUI to create a table so thats its not> so confusingQue?This appears to be a totally different question now.
cotton.ma at 2007-7-21 21:35:52 > top of Java-index,Java Essentials,Java Programming...
# 16

> i mean using a GUI to create a table so thats its not so confusing

You mean not so confusing for the people who are going to use it? Sure, good idea, go ahead and write it. Or buy it, if that's more practical.

Or you mean not so confusing for you? In that case you'll have to buy it. But there aren't any products that read your mind and generate the SQL you would have generated if you knew SQL.

DrClapa at 2007-7-21 21:35:52 > top of Java-index,Java Essentials,Java Programming...
# 17
ok cool i figured it out :). but now do i need a prepared statement like the other fields?
Alex1989a at 2007-7-21 21:35:52 > top of Java-index,Java Essentials,Java Programming...
# 18
bump
Alex1989a at 2007-7-21 21:35:52 > top of Java-index,Java Essentials,Java Programming...