• 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

writing Queries on JTable

 
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 All,

i have a doubt regarding Jtable
can we write queries based on the values of jtable?

like if you think a jtable as a database table,
can we prepare some queries and write to make it work on the jtables?

 
Sheriff
Posts: 22784
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
Not out of the box, but it should be possible. I have written a ResultSet wrapper around a JTable, but it doesn't have any filtering.

Writing a Statement / PreparedStatement for JTables, perhaps even Connection, should be possible, but it's not that easy. Especially the parsing of SQL queries can be tricky.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if by "writing queries" you mean to sort and/or filter the data in the JTable, do a serch for :

javax.swing.table.TableRowSorter
javax.swing.RowSorter
javax.swing.RowFilter

RowFilter.regexFilter() lets you create filters using regular expressions.
 
L Ganesh
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my intention to write queries on jtable is to select a subset of values and display pie/bar charts out of it.

 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JTable gets its data from TableModel. I am assuming the TableModel in your case is not database backed, or otherwise you would simply get the data from the database. There has to be some kind of underlying Collection object (instance variable of TableModel) that is holding the data. I found this open source project that could help you write queries against the underlying collection at http://josql.sourceforge.net/

I have never used it but it seems like exactly what you are looking for.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic