H2: how to tell if table exists?

First: check the case in which you type tables’ names. It’s very important. word_types and WORD_TYPES are two different tables. Second: If you want to check if table exists and if it doesn’t then create one, I recommend you to use the following example: CREATE TABLE IF NOT EXISTS TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));

create if not exists view?

From section 12.1.12. CREATE VIEW Syntax of the MySQL 5.0 Reference Manual: CREATE VIEW Syntax CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = { user | CURRENT_USER }] [SQL SECURITY { DEFINER | INVOKER }] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] CHECK OPTION] The CREATE VIEW statement creates … Read more

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>