1 /* 2 * Copyright 2002-2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.ResultSet; 20 import java.sql.SQLException; 21 22 /** 23 * An interface used by {@link JdbcTemplate} for mapping rows of a 24 * {@link java.sql.ResultSet} on a per-row basis. Implementations of this 25 * interface perform the actual work of mapping each row to a result object, 26 * but don't need to worry about exception handling. 27 * {@link java.sql.SQLException SQLExceptions} will be caught and handled 28 * by the calling JdbcTemplate. 29 * 30 * <p>Typically used either for {@link JdbcTemplate}'s query methods 31 * or for out parameters of stored procedures. RowMapper objects are 32 * typically stateless and thus reusable; they are an ideal choice for 33 * implementing row-mapping logic in a single place. 34 * 35 * <p>Alternatively, consider subclassing 36 * {@link org.springframework.jdbc.object.MappingSqlQuery} from the 37 * <code>jdbc.object</code> package: Instead of working with separate 38 * JdbcTemplate and RowMapper objects, you can build executable query 39 * objects (containing row-mapping logic) in that style. 40 * 41 * @author Thomas Risberg 42 * @author Juergen Hoeller 43 * @see JdbcTemplate 44 * @see RowCallbackHandler 45 * @see ResultSetExtractor 46 * @see org.springframework.jdbc.object.MappingSqlQuery 47 */ 48 public interface RowMapper { 49 50 /** 51 * Implementations must implement this method to map each row of data 52 * in the ResultSet. This method should not call <code>next()</code> on 53 * the ResultSet; it is only supposed to map values of the current row. 54 * @param rs the ResultSet to map (pre-initialized for the current row) 55 * @param rowNum the number of the current row 56 * @return the result object for the current row 57 * @throws SQLException if a SQLException is encountered getting 58 * column values (that is, there's no need to catch SQLException) 59 */ 60 Object mapRow(ResultSet rs, int rowNum) throws SQLException; 61 62 } 63