0

Please pardon me, if my question is not complete. I am quite new to the Java world and just starting. I have been trying to learn about microservices and was creating the age-old currency exchange and currency conversion microservices application. I am at a point, wherein the currencyexchange is to have an In-memory DB created. However, the initialization fails and the tables are not created. I did dig around for the error, however, Im unable to spot on the exact issue. My pom.xml is:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.3</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.infratute.currency.exchange</groupId>
        <artifactId>currency-exchange</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>currency-exchange</name>
        <description>Demo Project for Dockerizing Microservices</description>
        <properties>
            <java.version>11</java.version>
            <spring-cloud.version>2021.0.0</spring-cloud.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

My CurrencyExchangeRate.java is:

    package com.infratute.currency.exchange.currencyexchange.controller.entity;
    import java.math.BigDecimal;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    
    
    @Entity
    public class CurrencyExchangeRate {
        
        @Id
        private int id;
        
        @Column(name="exchange_from")
        private String from;
        
        @Column(name="exchange_to")
        private String to;
        
        private BigDecimal exchangeRate;
        
        private int port;
        
        protected CurrencyExchangeRate() {
            
        }
        public CurrencyExchangeRate(int id, String from, String to, BigDecimal exchangeRate) {
            super();
            this.id = id;
            this.from = from;
            this.to = to;
            this.exchangeRate = exchangeRate;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getFrom() {
            return from;
        }
        public void setFrom(String from) {
            this.from = from;
        }
        public String getTo() {
            return to;
        }
        public void setTo(String to) {
            this.to = to;
        }
        public BigDecimal getExchangeRate() {
            return exchangeRate;
        }
        public void setExchangeRate(BigDecimal exchangeRate) {
            this.exchangeRate = exchangeRate;
        }
        public int getPort() {
            return port;
        }
        public void setPort(int port) {
            this.port = port;
        }
        
    }

My Controller is Currencyexchangecontroller.java:

    package com.infratute.currency.exchange.currencyexchange.controller;
    
    import java.math.BigDecimal;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.core.env.Environment;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.infratute.currency.exchange.currencyexchange.controller.entity.CurrencyExchangeRate;
    
    @RestController
    public class Currencyexchangecontroller {
        
        
        @Autowired
        Environment environment;
        
        @GetMapping("/currency-service/from/{from}/to/{to}")
        public CurrencyExchangeRate getCurrencyExchangeRate(@PathVariable String from, @PathVariable String to) {
            
            CurrencyExchangeRate currencyExchangeRate = new CurrencyExchangeRate(1001, "USD", "INR", BigDecimal.valueOf(74));
            currencyExchangeRate.setPort(Integer.parseInt(environment.getProperty("local.server.port")));
            return currencyExchangeRate;
            
        }
        
    }

My application.properties are :

    spring.application.name = exchange-service
     spring.config.import=optional:configserver:
     server.port = 8001
     spring.jpa.show-sql=true
     spring.h2.console.enabled=true
     spring.h2.console.settings.web-allow-others=true

My data.sql file is as below:

    INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
    VALUES(1001, 'USD, 'INR', 75, 0 );
    
    INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
    VALUES(1001, 'EUR, 'INR', 85, 0 );
    
    INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
    VALUES(1001, 'GBP, 'INR', 102, 0 );
    
    INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
    VALUES(1001, 'CAD, 'INR', 59, 0 );
    
    INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
    VALUES(1001, 'AUD, 'INR', 54, 0 );

With this configuration, when I start the application, it fails as below:

07:04:06.641 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7d528c7b

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.3)

2022-02-16 07:04:07.993  INFO 69941 --- [  restartedMain] c.i.c.e.c.CurrencyExchangeApplication    : Starting CurrencyExchangeApplication using Java 11.0.13 on localhost.localdomain with PID 69941 (/home/vroot1/docker/projects/cu-ex-se/currency-exchange/target/classes started by vroot1 in /home/vroot1/docker/projects/cu-ex-se/currency-exchange)
2022-02-16 07:04:07.994  INFO 69941 --- [  restartedMain] c.i.c.e.c.CurrencyExchangeApplication    : No active profile set, falling back to default profiles: default
2022-02-16 07:04:08.095  INFO 69941 --- [  restartedMain] o.s.b.context.config.ConfigDataLoader    : Fetching config from server at : http://localhost:8888
2022-02-16 07:04:08.095  INFO 69941 --- [  restartedMain] o.s.b.context.config.ConfigDataLoader    : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2022-02-16 07:04:08.096  WARN 69941 --- [  restartedMain] o.s.b.context.config.ConfigDataLoader    : Could not locate PropertySource ([ConfigServerConfigDataResource@59fa3b92 uris = array<String>['http://localhost:8888'], optional = true, profiles = list['default']]): I/O error on GET request for "http://localhost:8888/exchange-service/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2022-02-16 07:04:08.106  INFO 69941 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-02-16 07:04:08.106  INFO 69941 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-02-16 07:04:09.751  INFO 69941 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-02-16 07:04:09.771  INFO 69941 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.
2022-02-16 07:04:10.077  INFO 69941 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=304ec315-dfdf-38f2-a007-59b03a83758a
2022-02-16 07:04:11.325  INFO 69941 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8001 (http)
2022-02-16 07:04:11.343  INFO 69941 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-02-16 07:04:11.343  INFO 69941 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-02-16 07:04:11.552  INFO 69941 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-02-16 07:04:11.553  INFO 69941 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3446 ms
2022-02-16 07:04:11.786  INFO 69941 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-02-16 07:04:12.120  INFO 69941 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-02-16 07:04:12.153  INFO 69941 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:a2ae51d8-784f-489e-9abc-e1c0a32added'
2022-02-16 07:04:12.414  WARN 69941 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/home/vroot1/docker/projects/cu-ex-se/currency-exchange/target/classes/data.sql]: INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CURRENCY_EXCHANGE_RATE" not found; SQL statement:
INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ) [42102-200]
2022-02-16 07:04:12.415  INFO 69941 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-02-16 07:04:12.429  INFO 69941 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2022-02-16 07:04:12.440  INFO 69941 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-02-16 07:04:12.555  INFO 69941 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-16 07:04:12.603 ERROR 69941 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/home/vroot1/docker/projects/cu-ex-se/currency-exchange/target/classes/data.sql]: INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CURRENCY_EXCHANGE_RATE" not found; SQL statement:
INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ) [42102-200]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar:2.6.3]
    at com.infratute.currency.exchange.currencyexchange.CurrencyExchangeApplication.main(CurrencyExchangeApplication.java:10) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.3.jar:2.6.3]
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/home/vroot1/docker/projects/cu-ex-se/currency-exchange/target/classes/data.sql]: INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CURRENCY_EXCHANGE_RATE" not found; SQL statement:
INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ) [42102-200]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:282) ~[spring-jdbc-5.3.15.jar:5.3.15]
    at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:254) ~[spring-jdbc-5.3.15.jar:5.3.15]
    at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:54) ~[spring-jdbc-5.3.15.jar:5.3.15]
    at org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer.runScripts(DataSourceScriptDatabaseInitializer.java:90) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.runScripts(AbstractScriptDatabaseInitializer.java:145) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.applyScripts(AbstractScriptDatabaseInitializer.java:107) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.applyDataScripts(AbstractScriptDatabaseInitializer.java:101) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.initializeDatabase(AbstractScriptDatabaseInitializer.java:76) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.afterPropertiesSet(AbstractScriptDatabaseInitializer.java:65) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15]
    ... 23 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CURRENCY_EXCHANGE_RATE" not found; SQL statement:
INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT) VALUES(1001, 'USD, 'INR', 75, 0 );

INSERT INTO currency_exchange_Rate(ID, exchange_from, exchange_to, exchangeRate, PORT)
VALUES(1001, 'EUR, 'INR', 85, 0 ) [42102-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableOrView(Parser.java:7628) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableOrView(Parser.java:7599) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseInsert(Parser.java:1747) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parsePrepared(Parser.java:954) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:843) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:815) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.prepareCommand(Parser.java:738) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareLocal(Session.java:657) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareCommand(Session.java:595) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201) ~[h2-1.4.200.jar:1.4.200]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-4.0.3.jar:na]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:261) ~[spring-jdbc-5.3.15.jar:5.3.15]
    ... 33 common frames omitted

I can understand that the exchangeRate needs to be changed on the data.sql file, however, I am quite unsure the cause of the error, as to why the init of the app fails. Any assistance is much appreciated.

Thanks in Advance.

Stan
  • 33
  • 8
  • See https://stackoverflow.com/questions/26881739/unable-to-get-spring-boot-to-automatically-create-database-schema – tgdavies Feb 16 '22 at 01:51

1 Answers1

1

The default naming strategy will transform your camel case variables to be separated with a _. So your column exchangeRate would be transformed in exchange_rate.

You mentioned that you knew that, but still, there it is not changed.

Secondly, add the datasource configurations in your .properties file:

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

This is needed to correctly create the connection.

Secondly, you must create the schema. data.sql file is used to insert (initialize) data. But schema creation is either made by an init.sql file or by Hibernate. To let Hibernate do that for you, add the following line to your properties file:

spring.jpa.hibernate.ddl-auto=create # or create-drop, update etc.

Try to thoroughly read your errors in your console, it stands there that your table could not be found.

Renis1235
  • 4,116
  • 3
  • 15
  • 27
  • I followed the above recommendations and have updated the application.properties file accordingly. However, what I notice is that the moment I add the data.sql file under the src/main/resources, the error starts, and the application restarts with the above error codes. The error remains the same and has not changed. Even before adding the INSERT... content to the data.sql file, the error pops up – Stan Feb 17 '22 at 01:32
  • Then try to create the Schema yourself through a `schema.sql` file. Check this https://stackoverflow.com/questions/38040572/spring-boot-loading-initial-data – Renis1235 Feb 17 '22 at 08:32