Results 1 to 4 of 4
  1. #1
    skywriter is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default 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:

    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 );
    		
    	}
    and the second:

    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);
    	}
    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?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    I wouldn't do that db work inside the table model...
    Too much like mixing display and db layers together.

  3. #3
    skywriter is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Oh right.
    Thanks for putting a link to the answer up.
    Even in Russian...:)

Similar Threads

  1. DefaultTableModel vs AbstractTableModel
    By chyrl in forum AWT / Swing
    Replies: 4
    Last Post: 05-02-2010, 12:10 PM
  2. Replies: 3
    Last Post: 11-07-2009, 05:25 PM
  3. how to inherit a customised
    By Java_Jedi in forum AWT / Swing
    Replies: 1
    Last Post: 04-12-2009, 03:21 AM
  4. Replies: 4
    Last Post: 04-01-2009, 02:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •