Hello all,

I have used this code throughout this application with no troubles. I am creating a datatable, and the data is a result set returned from a sql query to an oracle 11g database. I'm creating a TableModel class that overrides the AbstractTableModel so I can add fetures to it. I get errors when I try to assign my ResultSet object however. Here is the code:

class MyTableModel extends AbstractTableModel {

       Statement stmt = conn.createStatement();
       ResultSet rs;
// the following throws compilation error: "cannot find symbol, symbol: class rs, location class <where it resides in my app> <identifier exepected>

       rs = stmt.executeQuery(query);
       
       //the following is fine:
       ResultSetMetaData rsmd = rs.getMetaData();
       int numcols = rsmd.getColumnCount();
       int numrows;

       int i = 0;
       int k = 0;
       
//rs.next throws the same error as above
       while (rs.next()) {
           for (k = 0; k <= numcols; k++) {
                data[i][k] = rs.getString(k);
           }
           if (checked) {
               data[i][k + 1] = new Boolean(false);
           }
           i++;
                
        }
//Default Table Model overrides follow.

I have no idea why this is not recognizing an object that was created in the line of code right above it, or why rs will auto complete with the expected methods and members but java can't find the package it belongs to.

rs hasn't been declared elsewhere. (It would throw a different error if it had). Any ideas?

I encapsulated the above code into a class method, surrounded by a try-catch block. That worked

> data[k + 1] = new Boolean(false);

Better yet; data[i][k + 1] = Boolean.FALSE . Same result, no unnecessary object creation.

> data[k + 1] = new Boolean(false);

Better yet; data[i][k + 1] = Boolean.FALSE . Same result, no unnecessary object creation.

HA! I copied that code directly from the sun site. The JDBC / SQL stuff was mine (Although copied from another source initially). I'm not sure however, but the boolean value is meant to represent a checkbox in a Jtable that displays the sql data (I am adding a selection checkbox to the end.) The boolean value needs toreturn its type from a call to getColumnClass() I've overriden. Could that why the created it as an object? Traditinally, there is no such thing as a native "boolean" type.

> Could that why the created it as an object?

There is absolutely no valid reason as to why a Boolean object needs to be created if one already exists and is ready to use i.e. considering that a Boolean can have only two states: TRUE and FALSE and those two are already accounted by the public static fields TRUE and FALSE of the Boolean class.

> Traditinally, there is no such thing as a native "boolean" type.

There is a primitive type "boolean". The usage of the primitive wrapper type Boolean v/s the primitive type boolean boils down to the use case in consideration i.e. whether you have an array of primitives or an array of reference types.

This question has already been answered. Start a new discussion instead.