> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/languages/java/framework/spring/jdbctemplate.md).

# JDBC Template

```java
//[... initialize ...]

        final SimpleDataSourceFactory simpleDataSourceFactory = new SimpleDataSourceFactory("com.mysql.jdbc.Driver");
        final DataSource dataSource = simpleDataSourceFactory.createDataSource(jdbcUrl, user, pass);
        jdbcTemplate = new JdbcTemplate(dataSource);

        final DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
        transactionTemplate = new TransactionTemplate(transactionManager);
        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

//[... and then ...]

        transactionTemplate.execute(new TransactionCallback<Object>() {
            @Override
            public Object doInTransaction(TransactionStatus status) {
                jdbcTemplate.execute(...)     // will be executed in transaction
            }
        }
```

## Stored procedures

* <https://mkyong.com/spring-boot/spring-boot-jdbc-stored-procedure-examples/>
* <https://www.tutorialspoint.com/springjdbc/springjdbc\\_stored\\_procedure.htm>
