Java Reference
In-Depth Information
40
41
// update database connection status
connectedToDatabase = true ;
42
43
44
// set query and execute it
45
setQuery(query);
46
}
47
48
// get class that represents column type
49
public Class getColumnClass( int column)
throws IllegalStateException
50
{
51
// ensure database connection is available
if (!connectedToDatabase)
throw new IllegalStateException( "Not Connected to Database" );
52
53
54
55
// determine Java class of column
56
try
57
{
58
String className = metaData.getColumnClassName(column + 1 );
59
60
// return Class object that represents className
return Class.forName(className);
61
62
}
63
catch (Exception exception)
64
{
65
exception.printStackTrace();
66
}
67
68
return Object. class ; // if problems occur above, assume type Object
69
}
70
71
// get number of columns in ResultSet
72
public int getColumnCount()
throws IllegalStateException
73
{
74
// ensure database connection is available
75
if (!connectedToDatabase)
76
throw new IllegalStateException( "Not Connected to Database") ;
77
78
// determine number of columns
79
try
80
{
81
return metaData.getColumnCount();
82
}
83
catch (SQLException sqlException)
84
{
85
sqlException.printStackTrace();
86
}
87
88
return 0 ; // if problems occur above, return 0 for number of columns
89
}
90
Fig. 24.25 | A TableModel that supplies ResultSet data to a JTable . (Part 2 of 4.)
Search WWH ::




Custom Search