0

I am using spring boot and maven to build my user Onlineshop. I would like to access my h2-console database onlineshop but I am failing to login with everything left as default. Also the database onlineshop is not created. Spring Boot is not throwing any errors since am using embedded tomcat. Thanks in advance for your help.

Here is my dependency

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>runtime</scope>

application.properties

spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:onlineshop

Error

enter image description here

10
  • Is that the URL you are trying to connect? Commented Sep 5, 2019 at 15:38
  • No, I am connecting to localhost:8080//h2-console but once it fails that url is generated automatically Commented Sep 5, 2019 at 15:44
  • Try changing your JDBC URL to jdbc:h2:mem:testdb Commented Sep 5, 2019 at 15:49
  • jdbc:h2:mem:testd gives same error Commented Sep 5, 2019 at 15:52
  • I think you may remove the spring.datasource.url=jdbc:h2:mem:onlineshop from properties file because spring boot enables auto configuration Commented Sep 5, 2019 at 15:55

2 Answers 2

2

Set below properties in the application.properties

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:onlineshop;IFEXISTS=FALSE;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.path=/h2-console

IFEXISTS

By default, when an application calls DriverManager.getConnection(url, ...) with embedded URL and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new databases, and only allow to open existing databases. To do this, add ;IFEXISTS=TRUE to the database URL. In this case, if the database does not already exist, an exception is thrown when trying to connect

Sign up to request clarification or add additional context in comments.

5 Comments

with this answer localhost:8080//h2-console displays error
@Odwori please add spring.h2.console.enabled=true
can you clean and rebuild the project if it does not help then remove spring.h2.console.path=/h2-console
can you update the question with the application file to see updated properties with last error message or image
I have solved it by simply going for lower version of com.h2databse <version>1.3.170</version>. Thanks all for your willingness to help
0

I solved this by simply downgrading the com.h2database

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.170</version>
        <scope>runtime</scope>
    </dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.