Skip to content
Advertisement

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 in the prod

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 like [B@48f278eb. Feeding that through new String(ResultSet.getBytes(“new_id”), StandardCharsets.UTF_8) gives gobbledygook: �Oh�؆nr�Mz��. Answer The reason you see [B@48f278eb is because the resulting MD5 hash is in

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 “(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, ~, !~, NOT, LIKE, ILIKE, REGEXP, IS, IN, BETWEEN, AND, OR, ,, )”; SQL statement: I am kind new to h2 and sql statments

I get empty list from findAll Spring data and h2 data base while the database is not empty

I have a spring boot API project with h2 database. I added some data in the data.sql but the data wasn’t inserted into the database however tables are created successfully when I call the findAll API I get an empty list due to the database tables are empty. Application.properties data.sql Pom.xml Main Class Gateway.java Repository Controller project structure Answer Add

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 why ID is getting a null value. The User class

Advertisement