Results 1 to 4 of 4
- 10-19-2010, 07:50 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
The right way to inherit AbstractTableModel
I need 2 descendants of AbstractTableModel:
the first one uses "connection" object for creating it's "statement" object;
the second one composes "connection" object.
I assume the right beginning of the first class could be so:
and the second:Java Code:public class ResultSetTableModel extends AbstractTableModel { protected Statement statement; protected ResultSet resultSet; protected ResultSetMetaData metaData; protected int numOfRows; public ResultSetTableModel(Connection connection) throws SQLException { statement = connection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY ); }
But the issue is Java stricts to call ascendant's constructor only at the first string where "connection" object is not created yet. What should be the right desision?Java Code:public class ResultSetTableModelConnection extends ResultSetTableModel { Connection connection; public ResultSetTableModelConnection(String driver, String url, String query) throws SQLException, ClassNotFoundException { Class.forName(driver); connection = DriverManager.getConnection(url); super(connection); setQuery(query); }
- 10-19-2010, 10:26 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
I wouldn't do that db work inside the table model...
Too much like mixing display and db layers together.
- 10-19-2010, 10:43 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
Thank you for answer. I agree with you but the class "ResultSetTableModel" was taken from H.Deitel's book "Advanced Java 2 Platform".
Solved here.
- 10-19-2010, 11:28 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Similar Threads
-
DefaultTableModel vs AbstractTableModel
By chyrl in forum AWT / SwingReplies: 4Last Post: 05-02-2010, 12:10 PM -
Difference between Arraylist and Vector in abstractTableModel ?
By riddhik84 in forum New To JavaReplies: 3Last Post: 11-07-2009, 05:25 PM -
how to inherit a customised
By Java_Jedi in forum AWT / SwingReplies: 1Last Post: 04-12-2009, 03:21 AM -
Problem when adding values of the ResultSet to a AbstractTableModel
By Azuxard in forum AWT / SwingReplies: 4Last Post: 04-01-2009, 02:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks