3

This is my first spring boot application. I am trying to connect the database using h2-console. But when I trying to do it I am getting an error. The error is,

Database "/Users/MyName/test" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)

enter image description here

I have shown h2-conosle image above. I did not use any code in application.property file. As well as I have used below mentioned dependency also.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

First My port was 8080 Then also this not worked. After that, the port has been changed to 8082. even it not working.

user_v12
  • 559
  • 5
  • 15
  • This may help [Database does not exist](https://stackoverflow.com/questions/58298381/database-c-data-sample-not-found-and-ifexists-true-so-we-cant-auto-create-i) – Asmat K May 10 '20 at 20:45

5 Answers5

4

First approach

  1. Search for h2 in spring boot logs, there will be log like H2 console available at '/console'. Database available at 'jdbc :h2:mem:5bcffde7-27bd-4d59-9ad1-3bc12635f0bf'. Note: /console is the path, i chosen for h2-console in application.properties, this will vary according to the path you have chosen.
  2. Copy the url without single quotes and no spaces between them i.e jdbc:h2:mem:5bcffde7-27bd-4d59-9ad1-3bc12635f0bf.
  3. Enter this in the JDBC Url in h2-console.
  4. Then you should be able to connect to it.

The second and simpler approach

Configuring the h2 database url in application.properties without the need of spring randomly generating it.

spring.datasource.url=jdbc:h2:mem:testdb
Vishnupriya
  • 148
  • 9
  • A note for readers: application.properties is by default in src/main/resources of the project directory. – ryanwebjackson Mar 15 '22 at 17:32
  • Mine is working fine after changing my configuration to `testdb`. Before it was `spring.datasource.url=jdbc:h2:mem:dcbapp` and I change it to what @Vishnupriya proposes in his solution which is `spring.datasource.url=jdbc:h2:mem:testdb` – stic-lab Feb 09 '23 at 12:05
0

The easy way to fix the problem may be to change the JDBC URL to jdbc:h2:mem:testdb

Another way to fix the issue is to add a version number with the maven dependency (from https://mvnrepository.com/artifact/com.h2database/h2). If you could add the dependency like below and rerun the application, the URL will be corrected.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.200</version>
    <scope>test</scope>
 </dependency>


    
sasikumar
  • 1
  • 2
0

One more easy way to create the database in Windows is when you run the C:\Program Files (x86)\H2\bin h2w.bat, you get a option as shown in the screen shots. You can create the database using the option Create a new database. And then use the same connection details to connect to the newly created h2 database.

Windows Screenshot

Windows Db Creation Screenshot

0

Try creating the file test.mv.db in your home directory - worked for me. Seems H2 sometimes has trouble creating files for an unknown reason. Please comment if you know why.

E.g.

PS> ni c:\users\<your user>\test.mv.db

Found here in unselected answer to a similar question.

Adam D.
  • 159
  • 1
  • 5
-1

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.url=jdbc:mysql://localhost:3306/alien

spring.datasource.username=root

spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 10 '23 at 14:34
  • The question is about h2, not mysql – ssimm Jun 28 '23 at 13:17