* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
ResultSetHandler implementation that returns a Map of Maps.
ResultSet rows are converted into Maps which are then stored
in a Map under the given key.
If you had a Person table with a primary key column called ID, you could retrieve rows from the table like this:
ResultSetHandler h = new KeyedHandler("id"); Map found = (Map) queryRunner.query("select id, name, age from person", h); Map jane = (Map) found.get(new Long(1)); // jane's id is 1 String janesName = (String) jane.get("name"); Integer janesAge = (Integer) jane.get("age");Note that the "id" passed to KeyedHandler and "name" and "age" passed to the returned Map's get() method can be in any case. The data types returned for name and age are dependent upon how your JDBC driver converts SQL column types from the Person table into Java types.
This class is thread safe.
<> The type of the key
this(convert, 1, null);
handle()to retrieve the key value from the current
ResultSetrow. This implementation returns
ResultSet.getObject()for the configured key column name or index.
// We assume that the user has picked the correct type to match the column
// so getObject will return the appropriate type and the cast will succeed.
handle()to store the current
ResultSetrow in some object. This implementation returns a
Mapwith case insensitive column names as keys. Calls to
map.get("col")return the same value.
rsResultSet to create a row from
java.sql.SQLExceptionif a database access error occurs