Skip to content

Tag: jdbctemplate

Write unit test for jdbcTemplate.batchUpdate() method

I have jdbcTemplate code, on which I am trying to write a unit test case. But the problem is I am unable to cover the full code. I am able to cover till: try{jdbcTemplate.batchUpdate(“update query”, new BatchPreparedStatementSetter(){ Test code snippet Please help. Answer Here the difficulty is that the new BatchPreparedStatementSetter(){ …} instance that contains the main logic that you

jdbctemplate count queryForInt and pass multiple parameters

How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this, But its showing queryForInt as strikes. Answer 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). As per spring docs int queryForInt(String sql, Map args) Deprecated. Query for an int

How to query for a List in JdbcTemplate?

I’m using Spring’s JdbcTemplate and running a query like this: There are no named parameters being passed, however, column name, COLNAME, will be passed by the user. Questions Is there a way to have placeholders, like ? for column names? For example SELECT ? FROM TABLEA GROUP BY ? If I want to simply run the above query and get