相关疑难解决方法(0)

通过Spring以服务器模式启动H2数据库

我试图通过Spring 在服务器模式下启动H2数据库(我希望它在不同的进程中运行).目前我正在使用java Runnable.exec启动h2数据库(使用命令:" java -cp h2.jar org.h2.tools.Server ")

我知道有一种方法可以通过Spring实现.我尝试将以下内容添加到spring配置中,但它不起作用(它没有启动H2数据库):

    <bean id="org.h2.tools.Server" class="org.h2.tools.Server"
        factory-method="createTcpServer" init-method="start" destroy-method="stop">
        <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
    </bean>

    <bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server"
        factory-method="createWebServer" init-method="start">
        <constructor-arg value="-web,-webAllowOthers,true,-webPort,8082" />
    </bean>
Run Code Online (Sandbox Code Playgroud)

我将不胜感激任何帮助/想法

spring h2 server-mode

12
推荐指数
1
解决办法
1万
查看次数

H2 控制台错误:找不到适合 08001/0 的驱动程序

您好,我在 H2 控制台数据库中查看我的架构时遇到问题:

我使用弹簧靴:

spring.datasource.initialize=true
spring.datasource.url=jdbc:h2:~/test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
Run Code Online (Sandbox Code Playgroud)

这是我的登录页面:

在此处输入图片说明

所以我在里面看到的是标准的控制台视图,没有我的表,但我的应用程序运行良好。

java spring h2 spring-boot

8
推荐指数
2
解决办法
6885
查看次数

如何在 Spring Boot 中启用 H2 数据库服务器模式

我正在使用带有使用 Spring Boot 的文件的 H2 数据库。

在我的 application.properties 中,我有这个条目:

spring.datasource.url=jdbc:h2:file:c:/Testprojekte/spring-boot-h2-db

但是现在我希望能够在运行应用程序时查看数据库,目前这是不可能的,因为我需要让数据库在服务器模式下运行才能这样做。在文档中,我发现我必须将 AUTO_SERVER=TRUE 添加到 URL 中,但这并不能解决问题。

那么,我需要更改什么才能同时从不同的进程连接到该数据库?

谢谢你的帮助!托尔斯滕

java h2 spring-data-jpa spring-boot

8
推荐指数
2
解决办法
5562
查看次数

如何使用Spring Boot将H2连接到远程数据库而不是嵌入模式?

对于我的小型Spring Boot应用程序,我在src/main/resources下有这个配置:

server.port = 8090
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.url = jdbc:h2:file:~/stapler
Run Code Online (Sandbox Code Playgroud)

我知道此配置已正确选取,因为应用程序启动日志中有有效的端口号8090.还有一个@PostConstruct initDb()方法,它创建数据并将数据插入该数据库的2个表中:

package com.avk.stapler.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class DbInitializer {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public static void main(String[] args) {
        SpringApplication.run(DbInitializer.class, args);
    }

    @PostConstruct
    private void initDb() {
        System.out.println("Creating table employees");
        jdbcTemplate.execute("drop table employees if exists");
        jdbcTemplate.execute("create table employees(id serial, name varchar(255), surname varchar(255))");
        jdbcTemplate.execute("insert into employees(name, surname) values('Jan', 'Kowalski')");
        jdbcTemplate.execute("insert into employees(name, surname) values('Stefan', 'Nowak')");


        System.out.println("Creating table allocations");
        jdbcTemplate.execute("drop …
Run Code Online (Sandbox Code Playgroud)

java h2 spring-data spring-boot

3
推荐指数
1
解决办法
9554
查看次数

其他工具无法访问内存数据库中的 Spring Boot

我正在尝试从 Intellij 控制台访问内存中的 H2 数据库。我正在使用 spring boot 来配置一切。连接字符串为:spring.datasource.url=jdbc:h2:mem:testdb

当我使用 intellij 连接到数据库时,我看不到或查询表。我可以运行一个创建表命令来获取它,但就是这样。这是该配置的图像:

在此处输入图片说明

SHOW TABLES 查询的结果不返回任何内容。

为什么我无法连接到这个数据库?

hibernate h2 spring-data-jpa spring-boot

3
推荐指数
1
解决办法
2464
查看次数

H2DB的默认URL和凭据?

我已经在springBoot应用程序中添加了H2DB以进行单元测试。

我在application-test.properties中添加了:

spring.datasource.name = h2db

spring.h2.console.enabled = true

它的工作正常,保存值。

但是它是如何工作的以及如何浏览该数据库?

spring-data-jpa h2db spring-boot

2
推荐指数
1
解决办法
2921
查看次数