如何使用自定义用户名/密码运行h2 db作为独立服务器?

时间:2018-03-13 22:31:14

标签: java tcp h2 h2db

我过去曾使用h2 db作为某些java应用程序的嵌入式数据库,但这次我想将它作为独立服务器(tcp)运行,我可以从另一个客户端连接,更改默认用户和密码< / p>

我下载了h2db,解压缩了zip,我在bin目录中看到了以下

h2-1.4.196.jar
h2.bat
h2.sh
h2w.bat

我阅读了文档,我发现启动控制台以及服务器我只需执行

./h2.sh -webAllowOthers -web -tcpAllowOthers

有了这个,我可以打开Web控制台,使用username = sa和密码=“”登录,但我找不到更改默认用户名和密码的方法

根据文档,可以通过在连接字符串

中添加值来完成
jdbc:h2:tcp://localhost/~/test;USER=sa1;PASSWORD=welcome

但是当我尝试从Web控制台打开连接时出现错误

Duplicate property "USER" [90066-196] 90066/90066

看起来用户是在服务器启动时定义的,我也读到有一个文件

.h2.server.properties

我可以找到服务器属性但我只看到这样的东西

12=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
13=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/~/test|sa

似乎用户名是在那里定义但没有密码,我找不到ant选项来定义服务器的参数

Server options
Supported options are:
[-web]   Start the web server with the H2 Console
[-webAllowOthers] Allow other computers to connect - see below
[-tcp]   Start the TCP server
[-tcpAllowOthers] Allow other computers to connect - see below
[-tcpPort <port>] The port (default: 9092)
[-tcpPassword <pwd>] The password for shutting down a TCP server
[-properties "<dir>"]   Server properties (default: ~, disable: null)
[-baseDir <dir>]  The base directory for H2 databases (all servers)

我已经尝试启动服务器,稍后控制台指向服务器,但仍然无法找到如何更改用户名或密码

启动服务器

java -cp h2-1.4.196.jar org.h2.tools.Server -web -tcp -webAllowOthers -tcpAllowOthers -tcpPassword welcome
TCP server running at tcp://10.157.196.152:9092 (others can connect)

连接服务器

./console.sh -url tcp://localhost:9092 -driver org.h2.Driver -user sa -password welcome

我的问题是:

如何定义用于访问Web控制台的默认用户名/密码?

0 个答案:

没有答案
相关问题