【问题标题】:H2 database console errorH2数据库控制台错误
【发布时间】:2019-01-15 19:26:00
【问题描述】:

您好,我是in-memory DB H2 的第一次用户。我使用以下配置从应用程序连接。我运行了应用程序,我看到日志中的变化。

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

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

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();
}

【问题讨论】:

  • 附言。始终尝试将错误消息/日志添加为文本,而不是图像。 :)

标签: java h2


【解决方案1】:

这里提到:

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

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

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

【讨论】:

    猜你喜欢
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    • 2020-04-12
    • 2018-04-23
    • 2013-08-23
    • 1970-01-01
    相关资源
    最近更新 更多