aspose file tools*
The moose likes JDBC and the fly likes Jtable and database results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Jtable and database results " Watch "Jtable and database results " New topic
Author

Jtable and database results

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125


i have a jtable made with netbeans, but when i press the button "search" the connection at db is done but the table is not populated
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
event.getSource()??

What dreadful non-object-oriented coding. Add the ActionListener to the button, and consider whether to do it as an object of another class, or an anonymous class.

Try adding a System.out.println() call in your while(rs.next()) loop, then you can see what the data retrieved are.
Never have an empty catch() block; if you suffer an Exception you will know nothing about it. Put something in that catch(); even e.printStackTrace(); will help no end.

Let's try moving you to the GUIs forum, because I think your problem is more to do with display than data retrieval.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Campbell Ritchie wrote:event.getSource()??

What dreadful non-object-oriented coding. Add the ActionListener to the button, and consider whether to do it as an object of another class, or an anonymous class.

Try adding a System.out.println() call in your while(rs.next()) loop, then you can see what the data retrieved are.
Never have an empty catch() block; if you suffer an Exception you will know nothing about it. Put something in that catch(); even e.printStackTrace(); will help no end.

Let's try moving you to the GUIs forum, because I think your problem is more to do with display than data retrieval.


yes i have my actionlistener for the button, but it is in the GUI class, it is needed to post it?

how can i go to GUIs forum? is not a cross posting?

btw just noticed this error

java.sql.SQLException: [Microsoft][Driver Manager ODBC] Stato del cursore non valido.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:51)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Invalid cursors are a JDBC issue. Moving there.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Rob Prime wrote:Invalid cursors are a JDBC issue. Moving there.
any idea?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Antony Amicone wrote:any idea?

My idea would be to look at the stack trace which you posted.

If you do that you will notice that the first line which refers to something in your code is calling a getString() method. There are three such lines in the code you posted; the line number in the stack trace will tell you which of the three it is. Look at that line and fix your code so that you are handling a result set cursor correctly.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
sorry but i'm not able to understand my error, can you just simply tell me how to correct and i'll understand better?
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i tryed that way, no more errors, but no result



Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i corrected many error, so i show my classes, please explain me why database is not shown





this is the error

java.lang.NullPointerException
at desktopapplication1.Datab.getColumnCount(Datab.java:37)
at javax.swing.JTable.createDefaultColumnsFromModel(JTable.java:1261)
at javax.swing.JTable.tableChanged(JTable.java:4383)
at javax.swing.JTable.setModel(JTable.java:3685)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:79)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
test2
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
at desktopapplication1.Datab.getColumnCount(Datab.java:37)
at javax.swing.table.TableRowSorter$TableRowSorterModelWrapper.getColumnCount(TableRowSorter.java:244)
at javax.swing.DefaultRowSorter.updateUseToString(DefaultRowSorter.java:602)
at javax.swing.DefaultRowSorter.sort(DefaultRowSorter.java:556)
at javax.swing.DefaultRowSorter.allChanged(DefaultRowSorter.java:816)
at javax.swing.DefaultRowSorter.modelStructureChanged(DefaultRowSorter.java:826)
at javax.swing.JTable.tableChanged(JTable.java:4374)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
at javax.swing.table.AbstractTableModel.fireTableStructureChanged(AbstractTableModel.java:200)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:87)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
at desktopapplication1.Datab.getColumnCount(Datab.java:37)
at javax.swing.JTable.createDefaultColumnsFromModel(JTable.java:1261)
at javax.swing.JTable.tableChanged(JTable.java:4383)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
at javax.swing.table.AbstractTableModel.fireTableStructureChanged(AbstractTableModel.java:200)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:87)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
test2
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i tried modifing Datab() and putting there all the operation, and now the result is this


java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
at sun.jdbc.odbc.JdbcOdbcResultSet.last(JdbcOdbcResultSet.java:2291)
at desktopapplication1.Datab.<init>(Datab.java:29)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:78)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable and database results