• 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

inserting jtable into database

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends..i m using javax.swing.JTable..with defalutSetModel..it has three columns..i want to insert it into the mysql database.can i insert whole table in one column of database..please help me..
i m new to usiing the swings components
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you want to store the entire JTable, with all rows and columns, into one column?

Do you want to store each JTable row in a database row, or do you want to store all JTable rows into one single database row?

If you want to store the entire JTable into one row, you can serialize the JTable's TableModel into the database. Setting it using a PreparedStatement stmt:
Retrieving it from a ResultSet rs:

If you want to store each JTable row in a separate database row, you should create some object containing all the data (perhaps an Object[] or ArrayList<Object>), then store and retrieve that similar to the above.
In both cases the column must have a BLOB type.


A final word: I think it is bad design to merge objects from different rows (and perhaps even columns) into one single column (perhaps even cell). A JTable has a clear tabular structure, database tables have a very very similar tabular structure. You can map these one one one if you if the number of columns matches.
 
cchetan jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot rob for quick response..bt i m in trap that i want to save the row wise data of table into the database..bt there is a problem that in this case there is violation of rule of unique primary key..if you have any other idea to save this data in one unique id in database..then it will be very helpful to me
thanks in advance..
reply
    Bookmark Topic Watch Topic
  • New Topic