如何在服务器模式下运行H2数据库? [英] How to run H2 database in server mode?

查看:541
本文介绍了如何在服务器模式下运行H2数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在服务器模式下启动H2数据库。我需要从我的应用程序启动它。我尝试以下代码:

  server = Server.createTcpServer ; 

以下是连接的属性:

  javabase.jdbc.url = jdbc:h2:tcp:// localhost:9092 / nio:〜/ source / db / database / db; AUTO_SERVER = TRUE 
javabase。 jdbc.driver = org.h2.Driver
javabase.jdbc.username = sa
javabase.jdbc.password =

当我运行程序时,我得到以下错误:

  client.db.exception。 DAOException:org.h2.jdbc.JdbcSQLException:数据库可能已在使用:被另一个进程锁定。可能的解决方案:关闭所有其他连接;使用服务器模式[90020-164] 
在org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
在org.h2.message.DbException.get(DbException.java:169 )
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.store.FileLock.getExceptionAlreadyInUse(FileLock.java:439)
at org。 h2.store.FileLock.lockFile(FileLock.java:336)
at org.h2.store.FileLock.lock(FileLock.java:128)
at org.h2.engine.Database.open < init>(Database.java:217)
在org.h2.engine.Database中。
at org.h2.engine.Database.openDatabase(Database.java:222)
at org.h2.engine.Database。 )
at org.h2.engine.Engine.openSession(Engine.java:56)
at org.h2.engine.Engine.openSession(Engine.java:159)
at org。 h2.engine.Engine.createSessionAndValidate(Engine.java:138)
at org.h2.engine.Engine.createSession(Engine.java:121)
at org.h2.server.TcpServerThread.run TcpServerThread.java:133)
at java.lang.Thread.run(Thread.java:680)


$ b b

感谢,

解决方案

异常消息说数据库可能已在使用中。您需要关闭所有其他连接,以确保数据库不会在另一个进程中同时打开。



顺便说一下,不要使用AUTO_SERVER = TRUE 服务器模式。请参阅自动混合模式的文档。使用任一。



我想你对于不同的连接模式有点困惑。我建议您阅读有关连接模式的文档,以确保您了解它。 / p>

How to start H2 database in server mode. I need to start it from my application.I tried the following code:

server = Server.createTcpServer().start();

Here is the properties for the connection:

javabase.jdbc.url = jdbc:h2:tcp://localhost:9092/nio:~/source/db/database/db;AUTO_SERVER=TRUE
javabase.jdbc.driver = org.h2.Driver
javabase.jdbc.username = sa
javabase.jdbc.password =

When I run the program I got the following error:

client.db.exception.DAOException: org.h2.jdbc.JdbcSQLException: Database may be already in use: "Locked by another process". Possible solutions: close all other connection(s); use the server mode [90020-164]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.store.FileLock.getExceptionAlreadyInUse(FileLock.java:439)
    at org.h2.store.FileLock.lockFile(FileLock.java:336)
    at org.h2.store.FileLock.lock(FileLock.java:128)
    at org.h2.engine.Database.open(Database.java:542)
    at org.h2.engine.Database.openDatabase(Database.java:222)
    at org.h2.engine.Database.<init>(Database.java:217)
    at org.h2.engine.Engine.openSession(Engine.java:56)
    at org.h2.engine.Engine.openSession(Engine.java:159)
    at org.h2.engine.Engine.createSessionAndValidate(Engine.java:138)
    at org.h2.engine.Engine.createSession(Engine.java:121)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:133)
    at java.lang.Thread.run(Thread.java:680)

Thanks,

解决方案

As the exception message says, "Database may be already in use". You need to close all other connection(s), to make sure the database is not open in another process concurrently.

By the way, don't use AUTO_SERVER=TRUE and the server mode at the same time. See the documentation for the automatic mixed mode. Use either one.

I guess you are a bit confused about the different connection modes. I suggest to read the documentation about the connection modes, to make sure you understand it.

这篇关于如何在服务器模式下运行H2数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆