HSQLDB server mode username/password - java

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?

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.
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 update with additional information due to recent questions in comments:
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.
Other settings for a new database, such as hsqldb.tx=mvcc, can be appended to the database.0 string.
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.
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")
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")
See the Guide http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html for all the details.

Appears the problem you were running into (at least initially) is that, for HSQL in memory databases, if it's the "first" in memory database (i.e. process just started), the username "has to be" sa (username "sa" is not case sensitive, or it can be empty username, which implies the "default" which is also sa). You can use a blank password, or specify a password. Based on some trial and error, if you want to reconnect to the same (in memory) DB later, you'll have to re-use the same password (blank or otherwise). If you want to use a user other than SA you'd probably have to first connect to your database using SA and execute some "create user" type commands to create new users. 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);
Each new database you create follows the same system (it must be initial user SA and "adopts" whatever first password you give).
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.
Note that documentation also says "...This feature [default user SA] has a side effect that can confuse new users. If a mistake is made in specifying the path for connecting to an existing database, a connection is nevertheless established to a new database. For troubleshooting purposes, you can specify a connection property ifexists=true ..."

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 ""

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>

Related

Java MariaDB connection error: Access denied for user 'root'#'localhost' [duplicate]

This question already has answers here:
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
(43 answers)
Closed 3 years ago.
I wrote some function used by a php webpage, in order to interact with a mysql database. When I test them on my server I get this error:
"Connect failed: Access denied for user 'root'#'localhost' (using password: YES)"
I am able to use them on my pc (using XAMPP) and I can navigate through the tables of the database using the command line in the server. However, the webpage fails to connect. I've checked the password but with no results. It's correct (otherwise I could not log in to mysql from the command line).
The call of the function is the following:
$conn = new mysqli("localhost", "root", "password", "shop");
Do I have to set something in my server? Thanks
Edit:
PHP version 5.3.3-7+squeeze1
mysql version: 5.1.49-3
both on debian
I solved in this way:
I logged in with root username
mysql -u root -p -h localhost
I created a new user with
CREATE USER 'francesco'#'localhost' IDENTIFIED BY 'some_pass';
then I created the database
CREATE DATABASE shop;
I granted privileges for new user for this database
GRANT ALL PRIVILEGES ON shop.* TO 'francesco'#'localhost';
Then I logged out root and logged in new user
quit;
mysql -u francesco -p -h localhost
I rebuilt my database using a script
source shop.sql;
And that's it.. Now from php works without problems with the call
$conn = new mysqli("localhost", "francesco", "some_pass", "shop");
Thanks to all for your time :)
Is there a user account entry in the DB for root#localhost? In MySQL you can set different user account permissions by host. There could be several different accounts with the same name combined with the host they are connecting from. The most common are root#127.0.0.1 and root#localhost. These can have different passwords and permissions. Make sure root#localhost exist and has the settings you expect.
I am willing to bet, based on your explanation, that this is the problem. Connecting from another PC uses a different account than root#localhost and the command line I think connects using root#127.0.0.1.
From what you've said so far, it sounds like a problem where the MySQL driver in PHP5.3 has trouble connecting to the older MySQL version 4.1. Have a look on http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx
There's a similar question here with some useful answers, Cannot connect to MySQL 4.1+ using old authentication
SELECT `User`, `Host`, Length(`Password`) FROM mysql.user
This will return 16 for accounts with old passwords and 41 for accounts with new passwords (and 0 for accounts with no password at all, you might want to take care of those as well).
Either use the user managements tools of the MySQL front end (if there are any) or
SET PASSWORD FOR 'User'#'Host'=PASSWORD('yourpassword');
FLUSH Privileges
I had this problem too. But this was because of another reason.
My password began with character $... e.g. $MyPassword
I've changed it to #MyPassword and the problem is solved.
Easy.
open xampp control panel -> Config -> my.ini edit with notepad. now add this below [mysqld]
skip-grant-tables
Save. Start apache and mysql.
I hope help you
Here maybe?
I believe that the code should be:
$connect = new mysqli("host", "root", "", "dbname");
because root does not have a password. the (using password: YES) is saying "you're using a password with this user"
TIP:
comment out pid and socket file, if you can't connect to server..
mysql could be connecting with incorrect pid and/or socket file,
so when you try to connect to server trough command-line it "looks"
at the incorrect pid/socket file...
### comment out pid and socket file, if you can't connect to server..#pid-file=/var/run/mysql/mysqld.pid
#socket=/var/lib/mysql/mysql.sock
Most likely it is not identifying your user properly. root#localhost.
Select the Mysql version your MAMP is using.
/Applications/MAMP/Library/bin/mysqldump -uroot -p db_name > test_db_dump.sql
I actually wrote an alias on my computer so I don't have to remember how to get to the bin directory.
alias mysqldumpMAMP='/Applications/MAMP/Library/bin/mysqldump'
Which allows me to run this:
mysqldumpMAMP -uroot -p db_name > test_db_dump.sql
You can save an alias in your bash profile ~/.bash_profile or ~/.bash_rc
May be there password is not set and you are passing password as argument.
Try ommitting password argument during connection..
Edit your privileges on PHPmyAdmin (WAMP), Note that your password and user name has not been created. So do create or edit it, that it might work with your sql connection in your php.
Hope it works
Try initializing your variables and use them in your connection object:
$username ="root";
$password = "password";
$host = "localhost";
$table = "shop";
$conn = new mysqli("$host", "$username", "$password", "$table");

Changing Hadoop Username during runtime doesn't work

I wrote a little Hadoop Client Java application, that lists all files in HDFS (unsecure) and all tables in Hive, and some more stuff. However, I need to change the Hadoop Username during runtime.
Setting the name via System.setProperty("HADOOP_USER_NAME", "testuser"); works fine for the first time I need this username. But when I want to change the username to e.g. System.setProperty("HADOOP_USER_NAME", "hdfs"); I get an exception (after setting the hadoop username to hdfs as shown above):
org.apache.hadoop.security.AccessControlException: Permission denied: user=testuser, access=READ_EXECUTE, inode="/app-logs/ambari-qa":ambari-qa:hadoop:drwxrwx---
What could be the problem here? Why can't I just change the username via the HADOOP_USER_NAME property whenever I want to?
EDIT
Can I just use UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(username)); to change the user during runtime or are there some restrictions?
Because, you are connecting to HDFS or Hive using JDBC connection.
Till you close the existing connection , you cannot make one more connection from the same application to HDFS/Hive service .

createSQLException Error while in Configuring Data Source with Weblogic

I am trying to configure DataSources with WebLogic 10.3 and database is MySQL Server 5.5 , On entering the following
Driver Class Name ="com.mysql.jdbc.Driver"
url =jdbc:mysql://localhost:3306/weblogicdb
Database User Name =root (User name of Database MySql Server)
Password =123(Password name of Database MySql Server)
Confirm Password =123
and on clicking TestConfiguration, I get the following error.
Connection test failed.
Message icon - Error Unknown database 'weblogicdb'<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:930)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2864)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:806)
<br/>com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3263)
<br/>com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176)
<br/>com.mysql.jdbc.Connection.createNewIO(Connection.java:2638)
<br/>com.mysql.jdbc.Connection.<init>(Connection.java:1525)
<br/>com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:260)
<br/>com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:505)
<br/>com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:369)
<br/>sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br/>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
<br/>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br/>java.lang.reflect.Method.invoke(Method.java:597)
<br/>org.apache.beehive.netui.pageflow.FlowController.invokeActionMethod(FlowController.java:870)
<br/>org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward(FlowController.java:809)
<br/>org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowController.java:478)
<br/>org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(PageFlowController.java:306)
<br/>org.apache.beehive.netui.pageflow.FlowController.execute(FlowController.java:336)
<br/>org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute(FlowControllerAction.java:52)<br/>...
I was looking into many blogs and previously asked questions, where they it could be because of username and password being incorrect. But that is not the issue in my case, I have rechecked it. on using the same username and password, I was able to log into my MySQL database.
Kindly help me in configuring the system.
Error stack clearly says that:
Message icon - Error Unknown database 'weblogicdb'
It seems you have input a wrong database name.
You might be succeeding with username/passwords to MySQL server.
But the server might have multiple databases in it and 'weblogicdb' is not the correct database name you are trying to connect to.
To see what databases the MySQL Server has in it, execute the following command either using java or any other MySQL clients like MySQL command line, SQLyog, PHPMyAdmin etc.
show databases();
This statement should result all the databases available.
Identify the appropriate one for your program and use the same in your code.
To connect through java to execute the above statement, db url should be:
url =jdbc:mysql://localhost:3306/?user=usernamevalue&password=passwordvalue

Yet another "Access denied for user" error..but I can log in directly to remote server from command line

Java 1.7
Spring 3.1.1 with Spring-WS 2.1.1
Joda
Hibernate 3.6
MySQL 5.0.51a
Maven 3
Tomcat 7
Eclipse 3.7
Greetings all...
Just another 'Access denied for user 'foo'#'localhost' error being thrown by my webapp, but with a twist.
I run both an instance of MySQL on my (duh) local machine for development, and another on my remote server.
Both instances have a database 'mydb' and two tables with identical names and structures.
On the local instance I use root.
On the remote machine I have issued the following sequence:
CREATE USER 'fubar'#'localhost' IDENTIFIED BY 'mypwd';
CREATE USER 'fubar'#'%' IDENTIFIED BY 'mypwd';
CREATE USER 'fubar'#'my.remote.server.com' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'localhost' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'%' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'my.remote.server.com' IDENTIFIED BY 'mypwd';
FLUSH PRIVILEGES;
I've confirmed with a 'select * from mysql.db' that three new rows appear and that all the appropriate fields have 'Y' values.
On the local machine from within a Command Prompt pane I can issue:
mysql -u fubar -p -h my.remote.server.com ,
reply with the password and get connected to the remote db.
Executing my java program fails with the famous
'Access denied for user 'fubar'#'localhost'
when url is adjusted to point to remote server
Using the following as part of my db.properties file in my Eclipse project:
hibernate.connection.url=jdbc:mysql://localhost:3306/mydb
hibernate.connection.username=root
hibernate.connection.password=myrootpwd
execution works great
execution fails with the dreaded error when using this:
hibernate.connection.url=jdbc:mysql://my.remote.servier.com:3306/mydb
hibernate.connection.username=fubar
hibernate.connection.password=mypwd
So I am stumped. How is that I can connect directly to the remote instance of MySQL server using the command line but not in my db.properties file?
TIA,
Still-learning Stev
I got into the same issue and its the wrong password that created the whole issue...
You can use the standalone java program code in the below link to test your connection and make sure it works first...
http://www.mkyong.com/jdbc/how-to-connect-to-mysql-with-jdbc-driver-java/

Connecting to local instance of PostgreSql with JDBC

I have a running local instance of PostgreSql on a linux machine. When I use psql command from the shell I success to log in without any problem. I need to connect to the PostgreSql via the JDBC, but I don't know what exactly should I pass as url parameter to DriverManager.getConnection().
It should start with jdbc:postgresql: but what's going next?
I was told by the system group that a database with was created like user name. e.g. if my user is jutky a db named jutky was created, but when I try to open a connection to jdbc:postgresql:jutky I get an error
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "jutky"
:(
Additional info
When I login via the psql I'm not prompted for the password, so when I try to login via JDBC I pass an empty string as a password - is it correct, or should I pass null or something?
When I type psql --help in the shell I see among the rest this line:
Connection options:
-h, --host=HOSTNAME database server host or socket directory (default: "/var/run/postgresql")
So I understand that I connect to PostgreSql via a socket directory, does that matters something to the URL string in the JDBC?
EDIT
First thanks for the answers.
Second: its not first time I'm using JDBC and in particular not the first time I'm connecting to the PostgreSql from JDBC, so I know the general rules and I have read the documentations. However in the described case I'm not sure how exactly should I construct the connection string if the instance is running via the socket directory and what password should I provide. Because when I login via the psql I'm not prompted for password at all.
Thanks in advance.
In addition to other answers note that by default Postgres is configured to accept connections via Unix sockets with authentication based on your operating system account, that's why psql works fine and doesn't require the password.
JDBC connections are made over TCP/IP with password authentication, so you need to modify pg_hba.conf accordingly. For example, this line allows TCP/IP connections from the same machine to all databases for all users with password authentication:
host all all 127.0.0.1/32 md5
After adding this line jdbc:postgresql:databasename should work.
EDIT: You can't create a JDBC connection over Unix socket since PostgreSQL JDBC driver can only work over TCP/IP. The password you use when creating JDBC connection is the password assigned to your user. If you don't have it, you can assign it, for example, using ALTER USER command. See 19.3. Authentication methods.
See also:
19.1. The pg_hba.conf file
It's all explained in official documentation.
This is the relevant part:
String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true";
Connection conn = DriverManager.getConnection(url);

Categories

Resources