HSQLDB server mode username/password

。_饼干妹妹 提交于 2020-01-13 10:19:29

问题


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.

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

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?


回答1:


If you try this with 2.2.6, 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.

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=test;password=test
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.




回答2:


Appears the problem you were running into (at least initially) is that, for HSQL in memory databases, the username "has to be" sa (not case sensitive, or empty, which implies the "default" which is sa). You can use a blank password, or specify a password. If you specify a password, and want to reconnect to the same (in memory) DB later, you'll have to re-use the same password. If you want to use a user other than SA you'd probably have to first connect to your database and execute some "create user" type commands. Then reconnect using that user (assuming your DB is all in memory).

You can use multiple different in-memory databases (if that's what you're trying to accomplish by specifying a different user) like this:

// change the MySpecialTestDb String for multiple different in memory databases
// or reuse the same value
// to reconnect to a previously created in memory database [i.e. within the same process previously].
String DB_CONNECTION_STR = "jdbc:hsqldb:mem:MySpecialTestDb"; 
String DB_USERNAME_STR = "sa";
String DB_USERNAME_PASSWORD = "";
DriverManager.getConnection(DB_CONNECTION_STR, DB_USERNAME_STR, DB_USERNAME_PASSWORD);

ref: http://www.hsqldb.org/doc/1.8/guide/guide.html#advanced-chapter

Or if you want to just "reset" an in memory database, like between each unit test, see here.




回答3:


Point no 1) Whenever you create a DB, you have to specify the username and password. You can keep it both blank; But same username and password has to be used while connecting to server.

If you observe script file of your DB, you can see commands like :-

CREATE USER "usr" PASSWORD DIGEST '9003d1df22eb4d3820015070385194c8'
ALTER USER "usr" SET LOCAL TRUE
GRANT DBA TO "usr"

I had created DB with user name "usr" so it appeared in script file in those commands. Now while starting server I do not need to specify user name or password. It will IGNORE this information.

While connecting server you have to give exactly same username and password, you gave while creating DB.

Point no 2) Make sure that there is no space in path of your DB files. If there is space then enclose the whole path in double quotes. I struggled a lot to find out this silly mistake of mine.

Now if I start the server wil below command it starts correctly

1) Go to lib of HSQL

cd C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\hsqldb\lib

Then give command

java -cp hsqldb.jar org.hsqldb.Server -database.0 file:"C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\TmpDBLocation\myKauDB" -dbname.0 xdb

2) In other command prompt went to lib location

cd C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\hsqldb\lib

Then connected the Swing UI of HSQL DB by giving command in other command prompt window

java -cp hsqldb.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --URL jdbc:hsqldb:hsql://localhost/xdb --user "usr" --password ""



回答4:


In my brand new 2.3.2 installation, after clicking bin/runServer.bat, I managed to connect (with Squirrel) using:

URL: jdbc:hsqldb:hsql://localhost:9001
User: SA
Password: <blank>


来源:https://stackoverflow.com/questions/8817780/hsqldb-server-mode-username-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!