Java Reference
In-Depth Information
91
// get name of a particular column in ResultSet
92
public String getColumnName(int column)
throws IllegalStateException
93
{
94
// ensure database connection is available
95
if (!connectedToDatabase)
96
throw new IllegalStateException( "Not Connected to Database" );
97
98 // determine column name
99 try
100 {
101 return metaData.getColumnName(column + 1 );
102 }
103 catch (SQLException sqlException)
104 {
105 sqlException.printStackTrace();
106 }
107
108 return "" ; // if problems, return empty string for column name
109 }
110
111 // return number of rows in ResultSet
112
public int getRowCount()
throws IllegalStateException
113 {
114 // ensure database connection is available
115 if (!connectedToDatabase)
116 throw new IllegalStateException( "Not Connected to Database") ;
117
118 return numberOfRows;
119 }
120
121 // obtain value in particular row and column
122
public Object getValueAt( int row, int column)
123 throws IllegalStateException
124 {
125 // ensure database connection is available
126 if (!connectedToDatabase)
127 throw new IllegalStateException( "Not Connected to Database" );
128
129 // obtain a value at specified ResultSet row and column
130 try
131 {
132
133
134 }
135 catch (SQLException sqlException)
136 {
137 sqlException.printStackTrace();
138 }
139
140 return "" ; // if problems, return empty string object
141 }
resultSet.absolute(row + 1 );
return resultSet.getObject(column + 1 );
Fig. 24.25 | A TableModel that supplies ResultSet data to a JTable . (Part 3 of 4.)
Search WWH ::




Custom Search