001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jdbc.core;
018
019import java.sql.PreparedStatement;
020import java.sql.SQLException;
021
022/**
023 * General callback interface used by the {@link JdbcTemplate} class.
024 *
025 * <p>This interface sets values on a {@link java.sql.PreparedStatement} provided
026 * by the JdbcTemplate class, for each of a number of updates in a batch using the
027 * same SQL. Implementations are responsible for setting any necessary parameters.
028 * SQL with placeholders will already have been supplied.
029 *
030 * <p>It's easier to use this interface than {@link PreparedStatementCreator}:
031 * The JdbcTemplate will create the PreparedStatement, with the callback
032 * only being responsible for setting parameter values.
033 *
034 * <p>Implementations <i>do not</i> need to concern themselves with
035 * SQLExceptions that may be thrown from operations they attempt.
036 * The JdbcTemplate class will catch and handle SQLExceptions appropriately.
037 *
038 * @author Rod Johnson
039 * @since March 2, 2003
040 * @see JdbcTemplate#update(String, PreparedStatementSetter)
041 * @see JdbcTemplate#query(String, PreparedStatementSetter, ResultSetExtractor)
042 */
043@FunctionalInterface
044public interface PreparedStatementSetter {
045
046        /**
047         * Set parameter values on the given PreparedStatement.
048         * @param ps the PreparedStatement to invoke setter methods on
049         * @throws SQLException if an SQLException is encountered
050         * (i.e. there is no need to catch SQLException)
051         */
052        void setValues(PreparedStatement ps) throws SQLException;
053
054}