• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here are multiple JTables?
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS Stefan Wagner
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our Swing/AWT/SWT/JFace forum for filing because the question is more about JTables than JDBC>
 
reply
    Bookmark Topic Watch Topic
  • New Topic