< prev index next >

src/demo/share/jfc/TableExample/JDBCAdapter.java

Print this page




 108                     newRow.add(resultSet.getObject(i));
 109                 }
 110                 rows.add(newRow);
 111             }
 112             //  close(); Need to copy the metaData, bug in jdbc:odbc driver.
 113 
 114             // Tell the listeners a new table has arrived.
 115             fireTableChanged(null);
 116         } catch (SQLException ex) {
 117             System.err.println(ex);
 118         }
 119     }
 120 
 121     public void close() throws SQLException {
 122         System.out.println("Closing db connection");
 123         resultSet.close();
 124         statement.close();
 125         connection.close();
 126     }
 127 
 128     @Override
 129     protected void finalize() throws Throwable {
 130         close();
 131         super.finalize();
 132     }
 133 
 134     //////////////////////////////////////////////////////////////////////////
 135     //
 136     //             Implementation of the TableModel Interface
 137     //
 138     //////////////////////////////////////////////////////////////////////////
 139     // MetaData
 140     @Override
 141     public String getColumnName(int column) {
 142         if (columnNames[column] != null) {
 143             return columnNames[column];
 144         } else {
 145             return "";
 146         }
 147     }
 148 
 149     @Override
 150     public Class<?> getColumnClass(int column) {
 151         int type;
 152         try {
 153             type = metaData.getColumnType(column + 1);




 108                     newRow.add(resultSet.getObject(i));
 109                 }
 110                 rows.add(newRow);
 111             }
 112             //  close(); Need to copy the metaData, bug in jdbc:odbc driver.
 113 
 114             // Tell the listeners a new table has arrived.
 115             fireTableChanged(null);
 116         } catch (SQLException ex) {
 117             System.err.println(ex);
 118         }
 119     }
 120 
 121     public void close() throws SQLException {
 122         System.out.println("Closing db connection");
 123         resultSet.close();
 124         statement.close();
 125         connection.close();
 126     }
 127 






 128     //////////////////////////////////////////////////////////////////////////
 129     //
 130     //             Implementation of the TableModel Interface
 131     //
 132     //////////////////////////////////////////////////////////////////////////
 133     // MetaData
 134     @Override
 135     public String getColumnName(int column) {
 136         if (columnNames[column] != null) {
 137             return columnNames[column];
 138         } else {
 139             return "";
 140         }
 141     }
 142 
 143     @Override
 144     public Class<?> getColumnClass(int column) {
 145         int type;
 146         try {
 147             type = metaData.getColumnType(column + 1);


< prev index next >