Wrong user name or password [8004-73] trying to get H2 to start/stop within JUnit test/same JVM

9,463 views
Skip to first unread message

Gary S. Weaver

unread,
Jun 19, 2008, 5:02:40 PM6/19/08
to H2 Database
Hello!

Having a problem that is probably simple to solve, but I'm new to H2,
so I'm hoping you might see what I'm doing wrong.

I have a Maven 2 project using version 1.0.73 of H2:

pom.xml:
...
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.0.73</version>
<scope>test</scope>
</dependency>
...

Using the following code in a unit test:

...
import org.h2.tools.Server;
import org.h2.tools.RunScript;
...
public void testDbWorks() {
Server server = null;
try {
String[] args = new String[0];
server = Server.createTcpServer(args);
server.start();
String url = "jdbc:h2:~/test";
String user = "sa";
String password = "";
String fileName = "./sql/create_a_table.sql";
// charsetName can be "UTF-8" or null
String charsetName = "UTF-8";
boolean continueOnError = false;

// this is what fails
RunScript.execute(url, user, password, fileName,
charsetName, continueOnError);
}
catch (Throwable t) {
t.printStackTrace();
}
finally {
if (server!=null) {
server.stop();
}
}
}

and calling that test, I get an error:

org.h2.jdbc.JdbcSQLException: Wrong user name or password [8004-73]
at org.h2.message.Message.getSQLException(Message.java:103)
at org.h2.message.Message.getSQLException(Message.java:114)
at org.h2.message.Message.getSQLException(Message.java:77)
at org.h2.message.Message.getSQLException(Message.java:149)
at org.h2.engine.Engine.validateUserAndPassword(Engine.java:
246)
at org.h2.engine.Engine.getSession(Engine.java:115)
at org.h2.engine.Session.createSession(Session.java:241)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:87)
at org.h2.Driver.connect(Driver.java:57)
at java.sql.DriverManager.getConnection(DriverManager.java:
525)
at java.sql.DriverManager.getConnection(DriverManager.java:
171)
at org.h2.tools.RunScript.process(RunScript.java:249)
at org.h2.tools.RunScript.execute(RunScript.java:243)

at ...MyTest.testDbWorks(ActivityWindowDAOHibernateImplTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at org.unitils.UnitilsJUnit3.runTest(UnitilsJUnit3.java:98)
at junit.framework.TestCase.runBare(TestCase.java:130)
at org.unitils.UnitilsJUnit3.runBare(UnitilsJUnit3.java:65)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:
124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:
213)
at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:
140)
at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:
127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:
338)
at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:
997)

Any idea as to what username and password I should be using? I also
tried setting the password via ChangePassword before start(), but that
didn't help.

Thanks in advance,
Gary

Thomas Mueller

unread,
Jun 19, 2008, 5:10:32 PM6/19/08
to h2-da...@googlegroups.com
Hi,

> String url = "jdbc:h2:~/test";

You are using the embedded mode, with database files in user home directory.

> String user = "sa";
> String password = "";

..
> RunScript.execute(url, user, password, ...

This means you are using the user name 'sa' and an empty password.
Probably the database in the user home folder already exists, and the
password for 'sa' is different.

> Any idea as to what username and password I should be using?

It's up to you, but you always need to use the same password. Or you
delete the database files (if you don't need the database any more)
using the DeleteDbFiles tool?

> I also tried setting the password via ChangePassword before start(),

The ChangePassword tool is for file encryption and is unrelated to the
user password. Probably I will change the name of the tool, what about
'ChangeFileEncryption'?

Regards,
Thomas

Gary S. Weaver

unread,
Jun 20, 2008, 9:41:46 AM6/20/08
to H2 Database
> This means you are using the user name 'sa' and an empty password.
> Probably the database in the user home folder already exists, and the
> password for 'sa' is different.

Thanks! After deleting the database files (in this case ~/temp.*), I
got past that error. :) !

> Or you
> delete the database files (if you don't need the database any more)
> using the DeleteDbFiles tool?

Cool! Will definitely take advantage of that. Thanks for the tip!

Gary

Борис Галицкий

unread,
Jul 24, 2017, 5:46:55 AM7/24/17
to H2 Database, garys...@gmail.com
Its work until now!!! I have the same problem. Thank you for help!! I was playing with H2. Some time later i have to use H2 in tests. Its failed with (wrong username or password). So i go to google and find your advice to delete all dependencies with H2 and test and temp. After clearing c:\users everything starts to work ok! So the main thing is that H2 have some user and you have to delete it!

пятница, 20 июня 2008 г., 17:41:46 UTC+4 пользователь Gary S. Weaver написал:
Reply all
Reply to author
Forward
0 new messages