0

I have a sql script with insert commands and I want to load the data in the database with that script at the startup of the spring application. How can i do that?

My application.yml

datasource:
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password: root
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: MYSQL
    show-sql: true
    properties:
        hibernate.cache.use_second_level_cache: true
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: true
        hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

I have declared data.sql in src/main/resources/data.sql, but the data is not loaded in the database at runtime and application logs also doesn't give any errors.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
jait23
  • 71
  • 2
  • 8
  • Are you using spring boot? check this out: https://stackoverflow.com/questions/38040572/spring-boot-loading-initial-data – Monzurul Shimul Sep 15 '17 at 01:23
  • But, its not picking up the data.sql file – jait23 Sep 15 '17 at 02:08
  • Is that your actually `application.yml`? If so I doubt it will work as I would expect a `spring:` prefix before all. Also you are really using Spring Boot or are you configuring a `DataSource` manually? If so auto config will be disabled as well as initializing it. – M. Deinum Sep 15 '17 at 06:18

0 Answers0