jdbctemplate

keyHolder.getKey() return null

无人久伴 提交于 2020-07-18 03:50:10
问题 Why code from "Spring in action 5" don't work (keyHolder.getKey() return null, but entity is saved in DB)? private long savePizzaInfo(Pizza pizza) { pizza.setCreatedAt(new Date()); PreparedStatementCreator psc = new PreparedStatementCreatorFactory( "insert into PIZZA (name, createdAt) values (?, ?)", Types.VARCHAR, Types.TIMESTAMP ).newPreparedStatementCreator( Arrays.asList( pizza.getName(), new Timestamp(pizza.getCreatedAt().getTime()))); KeyHolder keyHolder = new GeneratedKeyHolder();

jdbcTemplate query() guaranteed to maintain resultset order?

╄→尐↘猪︶ㄣ 提交于 2020-07-05 09:14:20
问题 My question is similar to the one asked here: http://forum.springsource.org/showthread.php?84508-jdbctemplate.query()-sorted-result-set but a clear answer was not provided - an ArrayList does not guarantee order. Basically, I would like to know if the call returned by jdbcTemplate.query() guarantees the order of the resultset and if I can dump it into a LinkedList and pass it along :) Thanks! Edit: I should clarify that the query does include an order by clause, hence my requirements for a

jdbctemplate count queryForInt and pass multiple parameters

◇◆丶佛笑我妖孽 提交于 2020-06-11 20:13:33
问题 How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this, Integer count = this.jdbcTemplate .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2}); But its showing queryForInt as strikes. 回答1: Both queryForInt() and queryForLong() are deprecated since version 3.2.2 (correct me if mistake). To fix it, replace the code with queryForObject(String, Class). this.jdbcTemplate

jdbctemplate count queryForInt and pass multiple parameters

二次信任 提交于 2020-06-11 20:12:43
问题 How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this, Integer count = this.jdbcTemplate .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2}); But its showing queryForInt as strikes. 回答1: Both queryForInt() and queryForLong() are deprecated since version 3.2.2 (correct me if mistake). To fix it, replace the code with queryForObject(String, Class). this.jdbcTemplate

Map Custom JdbcTemplate query result in an Object

我是研究僧i 提交于 2020-05-14 12:05:06
问题 I new in java and try to use spring framework. I have a question. By example, I have table : employee (id_employee, name) employee_product (id_employee_product, id_employee, product_name) if I select an employee data from my Employee table, I can map it in a POJO model User and define the tables structure in that model, like this: public class Employee { private final int id_employee; private final String nama; public Employee(int id_employee, String nama){ this.id_employee = id_employee;

how can i implement a pagination in spring jdbcTemplate

末鹿安然 提交于 2020-05-13 11:51:26
问题 here is my following dao implementaion @Override public List<UserAddress> getAddresses(int pageid,int total) { String sql = "select * FROM user_addresses order by id desc limit "+(pageid-1)+","+total; List<UserAddress> userAddresses = jdbcTemplate.query(sql, new RowMapper<UserAddress>() { @Override public UserSessionLog mapRow(ResultSet rs, int rowNum) throws SQLException { UserAddress userAdd = new UserAddress(); userAdd.setId(rs.getInt("id")); userAdd.setId(rs.getString("city")); return

passing different types of arguments to jdbctemplate query

[亡魂溺海] 提交于 2020-05-09 01:26:42
问题 I am trying to retrieve records from the database by using where clause with few different types of arguments. This is the simple method which I wrote where I am passing breedId and gender as an arguments. public List<Dog> listByBreedIdAndGender(long breedId, String gender) { return query("SELECT * FROM dog_entity WHERE breed__id = ? AND gender = ?", new MapSqlParameterSource(":breedId", breedId) .addValue(":gender", gender)); } private List<Dog> query(String sql, MapSqlParameterSource