I'm trying to connect to an h2 database on my local machine to create a sql DataSource object. I'm running windows and i'm having some issues defining the path to the data file in my projects app.properties file.
Say the path to the local directory data file is:
D:\projects\myproject\data\project
How would one go about defining a connection url for this?
I've tried the many things including the following:
project.db.url = jdbc:h2:tcp://localhost\\\\D:\\projects\\myproject\\data\\project
Then I thought maybe it's the JDBC URL that's the issue, so I tried:
project.db.url = jdbc:h2:tcp:\\\\localhost\\\\D:\\projects\\myproject\\data\\project
Change application.properties
to the following:
spring.jpa.open-in-view=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
Set H2 Console to the following:
jdbc:h2:mem:testdb
As per documentation, default JDBC
connection string is
jdbc:h2:~/test
And, for TCP connection
jdbc:h2:tcp://localhost/~/test
==Update==
But, if you wanted to create/read h2 database to/from specific folder, then it should be
jdbc:h2:tcp://localhost/<path_to_database>
That means,
jdbc:h2:tcp://localhost/D:/myproject/data/project-name
Thanks @Sam for sharing info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With