Export data from H2 database into CSV

Try CSVWRITE This is perhaps all that you need: call CSVWRITE ( ‘C:/MyFolder/MyCSV.txt’, ‘SELECT * FROM MYTABLE’ ) You need to just run the call (mentioned above) in the browser based client of H2 that you are most likely using. Further reading: http://www.h2database.com/html/functions.html#csvwrite.

Spring Boot. @DataJpaTest H2 embedded database create schema

I had the same issue, I managed to resolve by creating schema.sql (in resources folder) with the content CREATE SCHEMA IF NOT EXISTS <yourschema> Documentation can be found here but imho the lack of real examples make it very complex. Warning: this script is also executed within the normal (not test) environment. Not mandatory, but … Read more

Access to h2 web console while running junit test in a Spring application

As this is probably going to be a test-debugging feature, you can add it at runtime with your @Before: import org.h2.tools.Server; /* Initialization logic here */ @BeforeAll public void initTest() throws SQLException { Server.createWebServer(“-web”, “-webAllowOthers”, “-webPort”, “8082”) .start(); } And then connect to http://localhost:8082/ Note: unless you need this to run as part of your … Read more

JPA/Hibernate support for migration?

I usually let Hibernate generate the DDL during development and then create a manual SQL migration script when deploying to the test server (which I later use for UAT and live servers as well). The DDL generation in Hibernate does not offer support for data migration at all, if you only do as much as … Read more

Are there any reasons why h2 database shouldn’t be used in production?

The main reasons not to use H2 (or HSQLDB, or Derby) for production are: Probability of critical bugs: compared to the ‘big’ databases Oracle, IBM DB 2, MS SQL Server, MySQL, PostgreSQL, the Java databases are relatively new and therefore possibly not as stable (have bugs). Please note this is true for all newer products, … Read more

How to use DESC command in H2 Database?

you can use the SHOW command just like: sql> show columns from users; “users” is the table name, the output would be something like: FIELD | TYPE | NULL | KEY | DEFAULT ID | INTEGER(10) | NO | PRI | (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_B66F0B87_5AAA_4421_88AC_1E8CAC372596) USERNAME | VARCHAR(45) | NO | | NULL PASSWORD | … Read more