Java Code Examples for org.springframework.jdbc.core.PreparedStatementSetter

Following code examples demonstrate how to use org.springframework.jdbc.core.PreparedStatementSetterfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.jdbc.core.PreparedStatementSetterand various code implementation of this class.

    private PreparedStatementSetter getPreparedStatementSetter(final Category category ) {
        return ps -> {
            int i = 0;
            ps.setInt(++i, category.getCat_id());
            ps.setString(++i, category.getCategory());
        };
    } 


    private PreparedStatementSetter getPreparedStatementSetter(final Client client) {
        return ps -> {
            int i = 0;
            ps.setInt(++i, client.getCl_id());
            ps.setString(++i, client.getCl_nick());
            ps.setString(++i, client.getCl_pass());
        };
    } 

Advertisement
Javadoc
General callback interface used by the JdbcTemplate class.

This interface sets values on

a java.sql.PreparedStatement provided by the JdbcTemplate class, for each of a number of updates in a batch using the same SQL. Implementations are responsible for setting any necessary parameters. SQL with placeholders will already have been supplied.

It's easier to use this interface than PreparedStatementCreator: The JdbcTemplate will create the PreparedStatement, with the callback only being responsible for setting parameter values.

Implementations do not need to concern themselves with SQLExceptions that may be thrown from operations they attempt. The JdbcTemplate class will catch and handle SQLExceptions appropriately. @author Rod Johnson @since March 2, 2003 @see JdbcTemplate#update(String, PreparedStatementSetter) @see JdbcTemplate#query(String, PreparedStatementSetter, ResultSetExtractor)

Read More
Advertisement