Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the jdbc connection string for h2 database?

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
like image 643
Sam Avatar asked Jan 23 '18 19:01

Sam


2 Answers

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
like image 160
Vishnu Mari Avatar answered Sep 23 '22 03:09

Vishnu Mari


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.

like image 25
Ravi Avatar answered Sep 21 '22 03:09

Ravi