本文介绍了HSQLDB服务器模式用户名/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用Java代码以服务器模式启动HSQLDB,则服务器启动将没有任何问题.但是,当我尝试通过Java代码或HSQLDB DatabaseManagerSwing连接到同一数据库时;我无法连接.

If I start the HSQLDB in server mode using my Java code, the server starts without any problem. However, when I try to connect to the same either through the Java code or through the HSQLDB DatabaseManagerSwing; I am unable to connect.

我在仅内存模式下使用user = conn1和password = conn1启动了服务器.但是当连接到服务器时,它给了我以下异常:

I started the server with user=conn1 and password=conn1 in memory-only mode. But when connecting to the server it gave me following exception:

java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification - not found: conn1

我只能通过输入user = SA和空白密码来进行连接.我在Windows7计算机上使用HSQLDB 2.2.5和JRE1.7.

I can only connect by giving user=SA and blank password. I am using HSQLDB 2.2.5 and JRE1.7 on Windows7 machine.

有人可以告诉我我在哪里做错了吗?

Can someone tell me where am I doing wrong?

推荐答案

如果在最新版本的HyperSQL中尝试使用这些服务器属性,由于服务器属性不正确,您可能会收到一条错误消息.属性"server.username"被指定为"server.username".和"server.password"无效.并且dbname.0属性必须为小写.

If you try these server properties with recent versions of HyperSQL, you will probably get an error message as your server properties are not correct. The properties "server.username" and "server.password" are not valid. And the dbname.0 property must be in lowercase.

如果要使用SA以外的用户名创建服务器数据库,则可以将用户名和密码附加到数据库路径:

If you want to create a server database with a user name other than SA, you can append the user and password to the database path:

server.database.0 = file:E:/DB/myDB;user=testuser;password=testpw
server.dbname.0 = mydb

关闭服务器后,无需包括用户名和密码.凭据仅用于创建数据库.之后,在与服务器建立连接时将检查凭据.

After the server is shutdown, there is no need to include the user and password. The credentials are used only to create the database. After that, the credentials are checked when a connection is made to the server.

2020更新,由于最近有评论中的问题,提供了更多信息:

2020 update with additional information due to recent questions in comments:

  1. 仅当通过启动服务器创建新数据库时,才考虑为database.0指定的用户名和密码.如果数据库文件在启动服务器之前存在,则用户名和密码是不必要的,将被忽略.

  1. The user name and password specified for database.0 are taken into account only when a new database is created by starting the server. If the database files exist before starting the server, user name and password are unnecessary and are simply ignored.

新数据库的其他设置(例如hsqldb.tx=mvcc)可以附加到database.0字符串.

Other settings for a new database, such as hsqldb.tx=mvcc, can be appended to the database.0 string.

您的服务器必须具有database.0的属性.如果服务器正在服务两个不同的数据库,则可以为database.1添加属性.

You must have properties for database.0 for your server. You can add properties for database.1 if your server is serving two different databases.

database.0指定的文件路径对于连接到服务器的用户是隐藏的.仅dbname.0值用于访问,例如:DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb;uer=testuser;password=testpw")

The file path specified for database.0 is hidden from the users that connect to the server. Only the dbname.0 value is used for access, for example:DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb;uer=testuser;password=testpw")

getConnection调用中,最好分别说明用户名和密码以保持代码清晰:DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb", "testuser", "testpw")

In the getConnection call, it is better to state the user and password separately to keep the code clear:DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb", "testuser", "testpw")

请参见指南 http://hsqldb.org/doc /2.0/guide/dbproperties-chapt.html 了解所有详细信息.

See the Guide http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html for all the details.

这篇关于HSQLDB服务器模式用户名/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 16:01