How to see all tables in my h2 database at localhost:8082?

I had the same issue and the answer seems to be really stupid: when you type your database name you shouldn’t add “.h2.db” suffix, for example, if you have db file “D:\somebase.h2.db” your connection string should be like “jdbc:h2:file:/D:/somebase“. In other way jdbc creates new empty database file named “somebase.h2.db.h2.db” and you see what you … Read more

Starting an H2 Database Server from Maven?

I was able to get it to work without using an external server just by adding the dependency to H2 via Maven and then using this bean: <bean id=”dataSource” class=”org.springframework.jdbc.datasource.DriverManagerDataSource”> <property name=”driverClassName” value=”org.h2.Driver”/> <property name=”url” value=”jdbc:h2:file:h2\db”/> <property name=”username” value=”sa”/> <property name=”password” value=””/> </bean> Then again, this required that I use a file-based DB instead of … Read more

How reliable is h2 database? [closed]

Will this pace be kept? That’s the plan. will it be supported by opensource community for long term? It’s hard to predict the future, I guess that’s why nobody replied to your question yet 🙂 I’m sure it will be supported, because enough people use it. H2 is used in many (open source and commercial) … Read more

Initialize database without XML configuration, but using @Configuration

The following lines of code inside your @Configuration class might work. @Value(“classpath:com/foo/sql/db-schema.sql”) private Resource schemaScript; @Value(“classpath:com/foo/sql/db-test-data.sql”) private Resource dataScript; @Bean public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) { final DataSourceInitializer initializer = new DataSourceInitializer(); initializer.setDataSource(dataSource); initializer.setDatabasePopulator(databasePopulator()); return initializer; } private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(schemaScript); populator.addScript(dataScript); return populator; }

Spring configuration for embedded H2 database for tests

With the reservation that I do not know if there is any tool that can inspect the database, I think that a simple solution would be to use the Spring embedded database (3.1.x docs, current docs) which supports HSQL, H2, and Derby. Using H2, your xml configuration would look like the following: <jdbc:embedded-database id=”dataSource” type=”H2″> … Read more

java ClassNotFoundException for org.h2.Driver

In my case (unrelated a bit, but worth mentioning), I added this to my maven pom, and the error message went away: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>xxx</version> <!– ex: 1.2.140 –> </dependency> or if you are only using h2 during unit testing: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>xxx</version> <!– ex: 1.2.140 –> <scope>test</scope> </dependency>

Spring’s embedded H2 datasource and DB_CLOSE_ON_EXIT

Specify parameter in JDBC url jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE Also for in-memory test database I suggest you to add DB_CLOSE_DELAY=-1, like this: jdbc:h2:mem:alm;MODE=Oracle;DB_CLOSE_DELAY=-1 To add JDBC connection url to embedded-dababase change it to: <bean id=”dataSource” class=”org.springframework.jdbc.datasource.SimpleDriverDataSource”> <property name=”driverClass” value=”org.h2.Driver”/> <property name=”url” value=”jdbc:h2:mem:test;MODE=Oracle;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE”/> <property name=”username” value=”sa”/> <property name=”password” value=””/> </bean> <jdbc:initialize-database data-source=”dataSource” ignore-failures=”DROPS”> <jdbc:script location=”classpath:schema_h2.sql” /> </jdbc:initialize-database>

Spring Data JPA Unable to locate Attribute with the given name

Try changing private String FirstName,LastName,Email; to private String firstName,lastName,email; It should work. findByFirstName in SubscriberRepository tries to find a field firstName by convention which is not there. Further reference on how properties inside the entities are traversed https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions

Defining a Foreign key constraint in H2 Databases

Two-step process Create the table without a foreign key CREATE TABLE PLANETICKETS( DESTINATION VARCHAR(10) NOT NULL, TICKETPRICE NUMERIC(8,2) NOT NULL, TOURISTINFO_ID INT ) Add the foreign key constraint ALTER TABLE PLANETICKETS ADD FOREIGN KEY (TOURISTINFO_ID) REFERENCES TOURISTINFO(TOURISTINFO_ID) One-step process CREATE TABLE PLANETICKETS( DESTINATION VARCHAR(10) NOT NULL, TICKETPRICE NUMERIC(8,2) NOT NULL, TOURISTINFO_ID INT, foreign key (TOURISTINFO_ID) … Read more