• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

TableModel problem

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys and girls,
I'm trying to implement a table model but keep getting a runtime error. The stack trace i get is :
Exception occurred during event dispatching:
java.lang.AbstractMethodError
at archivetool.ResultSetTableModel.<init>(ResultSetTableModel.java:40)
at archivetool.resultsTable2.init(resultsTable2.java:78)
at archivetool.resultsTable2.<init>(resultsTable2.java:56)
at archivetool.db_queryTool.goDB(db_queryTool.java:614)
at archivetool.db_queryTool$6.actionPerformed(db_queryTool.java:386)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3715)
at java.awt.Component.processEvent(Component.java:3544)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:926)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
and my code is

line 40 is :
results.last();
but commenting out this line just causes the eerror to appear on the next line.
Please can anyone help me
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phung,
If you want to implement an interface, you have to implement all the methods in this interface. Try to extends DefaultTableModel instead of implemet tableModel...
Good Luck!
Renee
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried to extend DefaultTableModel as suggested, but i'm still getting the same error when i run the program.
Has anyone got another suggestion?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
if I look to your code, then I would suggest, that you simply add a Default Constructor to it, I mean a constructor without any argument, which calls super().
In your existing constructor, you should call this() in your first line. Maybe this helps.
Anyway, you should extend from DefaultTableModel. In the most cases, this fits your needs.
Bye
Rene
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried using a default constructor but i still keep getting the same AbstractMethodError. I don't understand why i get this error.
Please can anyone help me?
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried your example especially your table model and for me it worked. The only thing I did, was replacing the ResultSet by a Vector. Of course, this is not the solution for you, but it tells me, that you are searching your error in the wrong class. You should better have a look to your implementation of your ResultSet. Maybe there is a method missing.
In my opinion, your TableModel is correct. You can leave it as it is.
Here is my Vector table model

Please have in mind, that this is simply a hack. It is not well coded. At least the vector is a bad example, but it does it's work. The table will contain values. And that's what I want.
Hope this helps you a bit.
Rene
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some doubt about JDBC+ JTable... How do we populate a table when table data comes from a database?
What I am doing now is to seperate JDBC from JTable.
Step 1: Use JDBC to get a data Vector and a column Vector and close connection after that. The structure of the data Vector is up to you, I have a tableData Object which matches a table in the database if the table is editable, or it's a Vector of Vecotr if the table is read only.
Step 2: Pass 2 Vector to my tableModel which is extends AbstractorTableModel.
Step 3: After users make some changes. Save the vector in my tableModel into database.
By following these steps, it's easy to debug and doesn't open the connection all the time. I am wondering if I am doing right or anyone has good ideas about how to do JDBC + JTable right. Thanks in advance.
Renee
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the stack trace does point to a line where i try to manipulate the result set, but i'm unsure of what to do next.
Could the problem be that the resultset is parsed to the ResultSetTableModel class?
Or can you suggest something else?
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds not bad to separate JDBC and JTable. I would do the same.
But maybe it will not solve the problem, because when you create your data structure (may it be a vector of vectors) then you have to use the same method, which crashs (ResultSet.last()).
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to call ResultSet.last() and manipulate the resultSet, then when you create the statement, you have to call Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE); You may try to see if your JDBC version support update-resultset function by the return value of yourResultSet.getConcurrency(). if it returns 1007, that means the resultset is ResultSet.CONCUR_READ_ONLY. if it returns 1008, it means ResultSet.CONCUR_UPDATABLE.
There are lots of examples in the book "JDBC API Tutorial and Reference, Second Edition"... Also there is a book call "JAVA Database" has lots of similar examples too.
Good Luck!
Renee
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the declaration of the resultset to :
Stmt = C.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
but i now get the AbstractMethodError on that line. Here is some of the code :

Also when i try to add the line
yourResultSet.getConcurrency();
The AbstractMethodError appears on that line.
This is very confusing
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of Driver are you using? Maybe you can post it to the JDBC forum since it's like a JDBC question...

Good Luck.
Renee
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've actually taken a different approach to the problem now, But i'm having trouble getting my table to appear in a scrollpane with scrollbars. The table, appears in the scrollpane, but no horizontal scrollbars appear when the table is obviously larger than the viewable area.
Please could someone take a look at my code and tell me why?

I know it's a lot of code, but i would be grateful for any help
[ May 16, 2002: Message edited by: Peter Phung ]
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please add the following line to your code:
resTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
At least for me it worked.
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene for the suggestion.
My application now works perfectly.
Thanks also to everyone else who made suggestions
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic