Bill L
Bill L

Reputation: 2846

Spring Boot -- not running data.sql on Start

I'm trying to run a simple H2 Spring project. I've used starter.spring.io to initialize a project with the web, JDBC, JPA, andH2` dependencies. I'm following along with in28minutes Spring Mastercourse.

All I'm trying to do is initialize one table on startup. I do the following in my data.sql:

CREATE TABLE person
(
   id integer not null,
   name varchar(255) not null,
   location varchar(255),
   birth_date timestamp,
   primary key(id)
);

My application.properties looks like this:

spring.h2.console.enabled=true

I haven't touched a single other file in the entire project. Just loaded a project, added those lines, and tried running it. For some reason, my table isn't being created. I've gone through the steps in the tutorial probably 15 times by this point and can't find what I'm doing wrong, any help would be greatly appreciated.

Edit: My JDBC URL is correct, as well as my driver class. I've checked those each time I tried re-running the steps

Upvotes: 1

Views: 2356

Answers (1)

GDF
GDF

Reputation: 157

With your exact dependency setup, and with your schema, I can see the data in the web console.

The predefined Generic H2 (embedded) settings should provide the right values, but you should input the following :

Driver Class : org.h2.Driver

JDBC URL : jdbc:h2:mem:testdb

User Name : sa

Password : <empty>

on the web console login page, as those are the defaults for an embedded h2 database.

If you don't see any issue in the startup log, this is most likely it.

Take note that H2 will not error out if you try to connect to a non-existent database.

e.g. : jdbc:h2:mem:db, jdbc:h2:mem:foobar will not produce any errors and connect to empty databases.

Upvotes: 1

Related Questions