Pivotal Knowledge Base


Initializing a Database Instance in Spring Framework using Large SQL Scripts Fail


 Product  Version
 Spring Framework  All


  • Cannot initialize a database in Spring Framework using large SQL scripts in <jdbc:initialize-data-source>.
  • Initializing the database using large SQL scripts in <jdbc:initialize-data-source> fails.
  • You see the error:

                     java.lang.OutOfMemoryError: Java heap space 


The ResourceDatabasePopulator is the specific class that is responsible for reading SQL scripts and populating it to the database. It is not intended to do heavy duty data loading and can be used only to initialize small databases, primarily for embedded demos.

To workaround this issue, break down large SQL scripts into smaller ones. For example:

<jdbc:initialize- data-source="dataSource">

<jdbc:script location="classpath:smaller-script-1.sql"/>

<jdbc:script location="classpath:smaller-script-2.sql"/>

Alternatively, you can also use the style pattern:

<jdbc:script location="classpath*:/sqlscriptfolder/*.sql"/>



Powered by Zendesk