目次 | 前の項目 | 次の項目 | JDBCTM ガイド: 入門 |
private java.util.Hashtable s2c;
// Maps strings to column indexes
private ResultSetMetaData md;
// Our metadata object.
public synchronized int findColumn(String columnName)
throws SQLException {
// Make a mapping cache if we don't already have one.
if (md == null) {
md = getMetaData();
s2c = new java.util.Hashtable();
}
// Look for the mapping in our cache.
Integer x = (Integer)s2c.get(columnName);
if (x != null) {
return (x.intValue());
}
// OK, we'll have to use metadata.
for (int i = 1; i < md.getColumnCount(); i++) {
if (md.getColumnName(i).equalsIgnoreCase(columnName)) {
// Success! Add an entry to the cache.
s2c.put(columnName, new Integer(i));
return (i);
}
}
throw new SQLException("Column name not found", "S0022");
}
// now the individual get-by-column-name methods are easy:
public String getString(String columnName) throws SQLException {
return (getString(findColumn(columnName)));
}
明示的に終了処理を行う必要のある JDBC オブジェクトに関する状態を JDBC ドライバが持っている場合は、ドライバでファイナライズメソッドをオブジェクトのために用意する必要があります。オブジェクトが不要であるとわかった場合、ガベージコレクタはこのファイナライズメソッドを呼び出します。これにより、ドライバは、オブジェクトを閉じたり、そのほかの終了処理を行う機会が得られます。ただし、ガベージコレクタが動作しているという保証はないので、ファイナライザの呼び出しに依存することはできません。