Spring Boot JdbcTemplate Configuration Example
Step-1:- Add dependency into pom.xml (Spring boot jdbc & database dependency) .
Step-2:- Add Datasource details in application.properties file
For more details :- See Spring Boot JdbcTemplate Example
Step-1:- Add dependency into pom.xml (Spring boot jdbc & database dependency) .
<!-- Spring boot jdbc dependency -->
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-jdbc</artifactid>
</dependency>
<!-- MySql dependency -->
<dependency>
<groupid>mysql</groupid>
<artifactid>mysql-connector-java</artifactid>
</dependency>
Step-2:- Add Datasource details in application.properties file
spring.datasource.name=jdbcTest
# Applicationn context name
server.contextPath=/springjdbc
# Here 'test' is the database name
#spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
#spring.datasource.username=root
#spring.datasource.password=root
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=none
#spring.datasource.initialize=false
#spring.datasource.url=jdbc:h2:file:~/jdbcTest;DB_CLOSE_ON_EXIT=FALSE;IFEXISTS=TRUE;DB_CLOSE_DELAY=-1;
#spring.jpa.hibernate.ddl-auto = update
Step-3:- Now we can use JDBCTemplate object in DAO by using @Autowired annotation
@Autowired
private JdbcTemplate jdbcTemplate;
For more details :- See Spring Boot JdbcTemplate Example
No comments:
Post a Comment