× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Answer from jguru:

Well java.sql.ResultSet does not offer any method to retrieve the amount of
rows that have been selected.
Now I have following ideas that I hope might help:

(1)It is recommended to retrieve the results into an abitray datastructure,
especially in case of pooled connections. Now ensure using a datastructure
that has an accessor method for its size.
(2)Another possibility would be to use a seperate prepared statement that
returns nothing but a count of the rows that will be selected.
i.e. select count(*) from myTable
Instead of * you can also use any column existing in myTable.
(3)A third way I could think of is to add the count(<column>) to the
request, thus retrieving the count of all rows as the first column of each
row.
i.e. select count(&lt;existing column&gt;),* from myTable
I am not sure if it really makes sense, but it's at least a possibility.


>>>
So, best thing to do is to load your rows into a Vector (of Vectors), let
getRowCount()
return the size of this Vector and use the Vector as data vector of your
JTable.

Hope this helps.

Geert Van Landeghem


-----Original Message-----
From: Mangavalli, Ramanujam [mailto:RamM@Mvmills.com]
Sent: mardi 21 mai 2002 15:19
To: 'java400-l@midrange.com'
Subject: RE: Custom Table Model.


Well, here is the code:
(getRowCount() returns 0).
public class ResultSetTableModel extends AbstractTableModel {
        private java.sql.ResultSet lResultSet;
        private java.sql.ResultSetMetaData lResultSetMetaData;
        protected final java.lang.String className = "ResultSetTableModel";
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:12:05 PM)
 * @param pResultSet java.sql.ResultSet
 */
public ResultSetTableModel(ResultSet pResultSet)
{
        setResultSet(pResultSet);

        try     {
                        lResultSetMetaData = lResultSet.getMetaData();
                }
        catch (Throwable thrownException)
                        {
                        System.out.println("Error occurred in class " +
className + " in constructor.\n");
                                thrownException.printStackTrace();
                        }

}

/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:31:24 PM)
 * @return int
 */
public int getColumnCount()
{
        try     {
                                return lResultSetMetaData.getColumnCount();
                        }
        catch (Throwable thrownException)
                        {

System.out.println(thrownException.getMessage());
                                System.out.println("Error occurred in class
name " + className + " in method getColumnCount()");
                                return 0;
                        }

}
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:21:03 PM)
 * @return java.lang.String
 * @param pColumnNumber int
 */
public String getColumnName(int pColumnNumber)
{
        try
                {
                                return
lResultSetMetaData.getColumnName(pColumnNumber + 1);
                }
        catch(Throwable thrownException)
                {
                        System.out.println(thrownException.getMessage());
                        System.out.println("Error occurred in class name " +
className + " in method getColumnName(int pColumnNumber");
                        return new Integer(pColumnNumber).toString();
                }

}
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:19:18 PM)
 * @return java.sql.ResultSetMetaData
 */
protected java.sql.ResultSetMetaData getLResultSetMetaData() {
        return lResultSetMetaData;
}
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:18:40 PM)
 * @return java.sql.ResultSet
 */
protected java.sql.ResultSet getResultSet() {
        return lResultSet;
}
/**
 * getRowCount method comment.
 */
public int getRowCount()
{
        try
                {
                        getResultSet().last();
                        return getResultSet().getRow();
                }

        catch (Throwable thrownException)
                {
                        System.out.println(thrownException.getMessage());
                        System.out.println("Error occurred in class name
ScrollableResultSetTableModel in method getValueAt()");
                        thrownException.printStackTrace();
                }

        return 0;
}
/**
 * getValueAt method comment.
 */
public Object getValueAt(int pRow, int pColumn)
{
        try
        {
                ResultSet lScrollableResultSet =getResultSet();
                //lScrollableResultSet.absolute(pRow + 1);
                lScrollableResultSet.next();

System.out.println((String)lScrollableResultSet.getObject(pColumn+1));
                return lScrollableResultSet.getObject(pColumn+1);

        }
        catch (Throwable thrownException)
        {
                System.out.println(thrownException.getMessage());
                System.out.println("Error occurred in class name
ScrollableResultSetTableModel in method getValueAt()");
                System.out.println("Parameters passed to method are row = "
+ pRow + ", column = " + pColumn);
                thrownException.printStackTrace();
                return null;
        }

}
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:18:40 PM)
 * @param newLResultSet java.sql.ResultSet
 */
protected void setResultSet(java.sql.ResultSet newLResultSet) {
        lResultSet = newLResultSet;
}
/**
 * Insert the method's description here.
 * Creation date: (5/17/2002 2:19:18 PM)
 * @param newLResultSetMetaData java.sql.ResultSetMetaData
 */
protected void setResultSetMetaData(java.sql.ResultSetMetaData
newLResultSetMetaData)
{
        lResultSetMetaData = newLResultSetMetaData;
}
}


_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.