Skip to content

Tag: h2

Use H2 as test DB in JUnit5

I’m developing an app in Spring Boot. I use a PostreSQL DB for production, and I want my JUnit 5 tests to run on a H2 memory DB. Problem is, after some configuration, the tests still don’t seem to run on the in-memory db: I can access entities from the prod db (a saved entity doesn’t persist…

How to display hashed MD5 value as text displayed in H2?

The H2 HASH function returns bytes, and SELECT HASH(‘MD5’, ‘test’) AS new_id FROM my_table; displays a text value: 098f6bcd4621d373cade4e832627b4f6 How to retrieve that same text value in Java? Using ResultSet.getBytes(“new_id”) gives the object’s address, something l…

My Spring JPA queries do not work with H2

This query below does not work and it generates me an exception When I used the MySQL database, the query worked fine. But now that I am using the H2 database, it suddenly does not work. Why? How do I fix this? Answer It would be better to use JPA. If you still wanna use nativeQuery, use like this:

org.h2.jdbc.JdbcSQLSyntaxErrorException h2 database java

Exception in thread “main” org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement “INSERT INTO SMTP_DATA(SMTP_SERVER, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROM, SMTP_TO) VALUES (DEMO.STMP.COM, DEMOUSERNAME, DEMOPASSWORD, FROMDEMO@[*]MAIL.COM, TODEMO@MAIL.COM);”; expected …

Error while saving user to h2 using springboot

I’m trying to register a user entity through an API and add it to “users” table in my local dB. I keep getting the error mentioned below. I am sending a POST request with the following body: It states the “NULL not allowed for column “ID”” but I don’t understand…