Tutorial by Examples

Some of the queryFor* methods available in JdbcTemplate are useful for simple sql statements that perform CRUD operations. Querying for Date String sql = "SELECT create_date FROM customer WHERE customer_id = ?"; int storeId = jdbcTemplate.queryForObject(sql, java.util.Date.class, custom...
int storeId = 1; DataSource dataSource = ... // JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * FROM customer WHERE store_id = ?"; List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, storeId); for(Map<String, Object> ...
DataSource dataSource = ... // JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * FROM customer"; SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); while(rowSet.next()) { String firstName = rowSet.getString("first_name"); String lastN...
JdbcTemplate also provides convenient methods to execute batch operations. Batch Insert final ArrayList<Student> list = // Get list of students to insert.. String sql = "insert into student (id, f_name, l_name, age, address) VALUES (?, ?, ?, ?, ?)" jdbcTemplate.batchUpdate(sql, n...
The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder ( '?') arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTempl...

Page 1 of 1