H2数据库控制台错误

时间:2018-08-08 13:40:55

标签: java h2

嗨,我是in-memory DB 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();
}

1 个答案:

答案 0 :(得分:1)

如此处所述:

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

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

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