gpt4 book ai didi

java - H2数据库控制台错误

转载 作者:行者123 更新时间:2023-12-02 10:55:56 24 4
gpt4 key购买 nike

您好,我是内存数据库 H2 的首次用户。我使用以下配置从应用程序进行连接。我运行了应用程序,并且在日志中看到了更改。

但是当我尝试查看 H2Console 中的更改并尝试连接时,它会显示如下所示。它无法连接。但是当我终止 java 应用程序并尝试连接时,它会毫无错误地连接,但我看不到已完成的更改(在应用程序运行期间插入的新行)

当应用程序仍在运行时,如何查看H2控制台中的变化?

enter image description here

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver">org.h2.Driver</property>
<property name="hibernate.connection.user">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:h2:~/h2schema/test</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>

App.java

 {
System.out.println( "Hello World!" );
Alien alien = new Alien("mk", "white", 26l);
Alien alien2 = new Alien("mk1", "white1", 26l);
Configuration configuration = new Configuration().configure().addAnnotatedClass(
Alien.class);
SessionFactory factory = configuration.buildSessionFactory();
Session session = factory.openSession();
Transaction transaction = session.getTransaction();
transaction.begin();
session.save(alien);
session.save(alien2);
System.out.println("-----------");
System.out.println("created user is "+alien);
System.out.println("created user is "+alien2);
System.out.println("-----------");
transaction.commit();
session.close();
}

最佳答案

正如这里提到的:

H2 database error: Database may be already in use: "Locked by another process"

H2已锁定,尝试使用TCP在服务器模式下运行

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

关于java - H2数据库控制台错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51748226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com