wood burning stoves*
The moose likes JDBC and the fly likes JTable & Database , design question, what do you think? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JTable & Database , design question, what do you think?" Watch "JTable & Database , design question, what do you think?" New topic
Author

JTable & Database , design question, what do you think?

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi guys,

Q: I have a JTable 5x10 I need to insert the content into a database (and later on retrieve it). Every record has a JTable and every record is unique (there are many records) the JTable will have its own table in the database (segmentsTable) and a KEY.

So: how do I place all the content into the table???

my solution, and please feel free to criticize this idea, is to get all information of each raw and insert it to the db.

like this:

public void save()
{
int row = table.getSelectedRow();
String col0 = table.getValueAt(row, 0).toString(); // Value of 0 is in this Variable
String col1 = table.getValueAt(row, 1).toString(); // Value of 1 is in this Variable
// and so on

// Do insert KEY + raw content
}

so basically I'll have to have a table with 10 attributes and each attribute will contain a raw.

What do you think? I am very new to db so I'm not sure this is the most efficient way to do this. if you know a better way to insert/update/select info from a jtable PLEAES let me know.

Thanks
Ppr
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Peter,
I'm a bit confused by the question. Is it that each row in the JTable corresponds to a row in the database? Or that there are multiple JTables?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
here are multiple JTables?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

If you use a JTable, you usally use a TableModel, and the JTable has to be in sync with the TableModel (with setValueAt).
When you store the data, you store the data from the TableModel (which is in sync with the JTable - which is a View on the data), and don't query the JTable.


http://home.arcor.de/hirnstrom/bewerbung
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
THANKS Stefan Wagner
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Moving to our Swing/AWT/SWT/JFace forum for filing because the question is more about JTables than JDBC>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable & Database , design question, what do you think?
 
Similar Threads
jtable
Color in JTable
JTable & Database , design question, what do you think?
JTable & Database , design question, what do you think?
JTable usage