spring-jdbc

Spring batch: JdbcPagingItemReader doesn't obtain page 1 onwards

余生长醉 提交于 2020-12-15 00:29:26
问题 Here my reader: @Bean public ItemReader<Unitat> itemReader(PagingQueryProvider queryProvider) { return new JdbcPagingItemReaderBuilder<Unitat>() .name("creditReader") .dataSource(this.dataSource) .queryProvider(queryProvider) .rowMapper(this.unitatMapper) .pageSize(2) .build(); } @Bean public SqlPagingQueryProviderFactoryBean queryProvider() { SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean(); provider.setDataSource(this.dataSource); provider.setSelectClause

Is it possible to use a instanced pojo to insert with a JDBC template?

时光怂恿深爱的人放手 提交于 2020-12-12 01:25:27
问题 Spring has the BeanPropertyRowMapper to pull from SQL on a select and map to a POJO object without having to make a custom row mapper. I'm hoping for the same but for an insert statement. But I'm unable to find an equivalent. public boolean addRenewalQuote(Quote quote) { String sql = "INSERT INTO Customers (internal_order_number, b_email, s_email, b_firstname) VALUES (?, ?, ?, ?);"; if(getTemplate().update(sql, quote) > 0) { return true; }else { return false; } } The quote string names match

Spring repository method which are returning Java 8 stream doesn't close JDBC connection

大城市里の小女人 提交于 2020-08-02 06:33:42
问题 I have a Spring data repository: @Repository interface SomeRepository extends CrudRepository<Entity, Long> { Stream<Entity> streamBySmth(String userId); } I am calling that method in some Spring bean: @Scheduled(fixedRate = 10000) private void someMethod(){ someRepository.streamBySmth("smth").forEach(this::callSomeMethod); } I am using MySQL database. And when I am running application after some successful method invocations it throws an exception: o.h.engine.jdbc.spi.SqlExceptionHelper : SQL

Spring: How to use KeyHolder with PostgreSQL

≡放荡痞女 提交于 2020-07-18 03:31:50
问题 Recently migrated to POSTGRESQL, I am trying to obtain the uniquely generated key on creating a new entry into the db table. The table screenstable looks like this: CREATE TABLE screenstable ( id serial NOT NULL, screenshot bytea, CONSTRAINT screen_id PRIMARY KEY (id ) ) The method that inserts data into screenstable is as follows: @Autowired NamedParameterJDBCTemplate template; public int insertImage(ImageBean imageBean){ String query = "insert into screenstable (screenshot) values (:image)"