简体   繁体   English

什么是h2数据库的jdbc连接字符串?

[英]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. 我正在尝试连接到本地计算机上的h2数据库以创建sql DataSource对象。 I'm running windows and i'm having some issues defining the path to the data file in my projects app.properties file. 我正在运行Windows,我在项目app.properties文件中定义了数据文件路径的一些问题。

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? 如何为此定义连接URL?

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: 然后我想也许这是问题的JDBC URL,所以我试过:

project.db.url = jdbc:h2:tcp:\\\\localhost\\\\D:\\projects\\myproject\\data\\project

As per documentation , default JDBC connection string is 根据文档 ,默认的JDBC连接字符串是

jdbc:h2:~/test  

And, for TCP connection 并且,对于TCP连接

jdbc:h2:tcp://localhost/~/test  

==Update== == ==更新

But, if you wanted to create/read h2 database to/from specific folder, then it should be 但是,如果你想创建/读取特定文件夹中的h2数据库,那么它应该是

 jdbc:h2:tcp://localhost/<path_to_database>

That means, 那意味着,

jdbc:h2:tcp://localhost/D:/myproject/data/project-name

Thanks @Sam for sharing info. 感谢@Sam分享信息。

Change application.properties to the following: application.properties更改为以下内容:

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: 将H2控制台设置为以下内容:

jdbc:h2:mem:testdb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM