Spring boot 2.1.0 Hikari CP bad password - spring-boot

So I updated my Spring Boot to 2.1.0, and now hikari is the default CP. According to some SO questions related to this I no longer needed to use the .hikari in my application.properties file. My properties file now looks like this:
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/deployHistory/deployHistory
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
Now if I use the driver manager directly, like this:
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(databaseUrl);
Statement stat = conn.createStatement();
stat.execute("create table ...)");
stat.close();
conn.close();
It all works fine, However, when I use the Spring Boot JDBC template, and do a simple:
jdbcTemplate.update(...);
I get an error:
2018-11-26 14:27:54.772 INFO 7349 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-11-26 14:27:56.059 ERROR 7349 --- [nio-8080-exec-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-197]
What is the way to fix this? All the pre-2.0.4 answers don't seem to work.

Related

H2 Database not found with message it's available [duplicate]

This question already has answers here:
Spring Boot default H2 jdbc connection (and H2 console)
(14 answers)
Closed 7 months ago.
I cannot login to my H2 Database event though i see the message that the database is available.
DEBUG [main] [Log Context: ] org.springframework.jdbc.datasource.DriverManagerDataSource:134 Loaded JDBC driver: org.h2.Driver
DEBUG [main] [Log Context: ] org.springframework.jdbc.datasource.DriverManagerDataSource:144 Creating new JDBC DriverManager Connection to [jdbc:h2:mem:testdb]
INFO [main] [Log Context: ] o.s.boot.autoconfigure.h2.H2ConsoleAutoConfiguration:68 H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
My application.properties file looks like this:
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
and the database not found error messsage looks like this:
I am using h2database version 2.1.214 and spring boot version 2.5.9
at first try to add next properties to the Data Base URL:
DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
Example:
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE

How can I override the JPA properties for multiple datasources for Integration tests?

I have sucessfully configured two datasources for two different databases and schemas in my Spring Boot application. Now, for the integration tests I want to use an embedded database (HSQL) and execute the tests there. I tried overriding the properties using the following file (/src/test/resources/application-test.properties)
eot.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
eot.datasource.username=sa
eot.datasource.password=sa
eot.datasource.url=jdbc:hsqldb:mem:test;DB_CLOSE_DELAY=-1
eot.datasource.hikari.pool-name=ptest-eot
eot.datasource.jpa.show-sql=true
eot.datasource.jpa.generate-ddl=true
eot.datasource.jpa.database-platform=org.hibernate.dialect.HSQLDialect
eot.datasource.jpa.properties.hibernate.ddl-auto=create
eot.datasource.jpa.properties.hibernate.dialect=org.hibernate.dialect.HSQLDialect
info.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
info.datasource.username=sa
info.datasource.password=sa
info.datasource.url=jdbc:hsqldb:mem:test;DB_CLOSE_DELAY=-1
info.datasource.hikari.pool-name=ptest-info
info.datasource.jpa.show-sql=true
info.datasource.jpa.generate-ddl=true
info.datasource.jpa.database-platform=org.hibernate.dialect.HSQLDialect
info.datasource.jpa.properties.hibernate.ddl-auto=create
info.datasource.jpa.properties.hibernate.dialect=org.hibernate.dialect.HSQLDialect
In the log I can see it picks up some of the properties. In my application.yml the pool's name is 'eot-pool' and when I run the tests it shows correctly as 'ptest-eot'.
2022-05-27 17:09:03.855 INFO 6592 --- [ Test worker] mx.com.gnp.crm.adfe.EotJpaConfiguration : org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#18a1fd92
2022-05-27 17:09:04.039 INFO 6592 --- [ Test worker] com.zaxxer.hikari.HikariDataSource : ptest-eot - Starting...
2022-05-27 17:09:04.845 INFO 6592 --- [ Test worker] com.zaxxer.hikari.pool.PoolBase : ptest-eot - Driver does not support get/set network timeout for connections. (característica no soportada)
2022-05-27 17:09:04.851 INFO 6592 --- [ Test worker] com.zaxxer.hikari.HikariDataSource : ptest-eot - Start completed.
But it's not overriding the JPA properties. It's not creating the schemas, tables, nor printing the SQL statements to the log.
I tried removing the 'properties' part. Using for example:
info.datasource.jpa.show-sql=true
info.datasource.jpa.hibernate.ddl-auto=create
info.datasource.jpa.hibernate.dialect=org.hibernate.dialect.HSQLDialect
But the JPA properties aren't being replaced.
When I run the tests, the log shows the wrong dialect (from the main application.yml file).
HHH000400: Using dialect: org.hibernate.dialect.DB2400Dialect
And when the tests runs:
SQL Error: -5501, SQLState: 42501
Because the schema and the table don't exist.
How can I override the JPA properties for integration tests when I have multiple datasources?
It seems you have a general application.yml file and a specific application-test.properties file for the test environment. I'm not sure if you can mix those file extensions, probably not. Either you choose to use .yml or .properties for both. Try to change the file name to application-test.yml. Also, to activate this specific test environment it's necessary to put this config in application.yml:
spring:
profiles:
active:test

Unable to connect non stop SQL from Spring boot applivcation

My project uses non stop SQL/MX as RDBMS database, a product from HP.I am not able to connect to the data source using Spring Boot's standard practice of defining JDBC URL, user, password inside application.properties file.
spring.datasource.driverClassName = com.tandem.sqlmx.SQLMXDriver
spring.datasource.url = jdbc:sqlmx:
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SqlmxDialect
spring.datasource.hikari.connection-test-query=SELECT 1 FROM $USER1.TLFM3SQL.IF09CSTB
This is the error:
com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for
connections. (com.tandem.sqlmx.SQLMXConnection.getNetworkTimeout()I)
JdbcEnvironmentInitiator: could not obtain connection to query metadata: Unable to resolve name
[org.hibernate.dialect.SqlmxDialect ] as strategy [org.hibernate.dialect.Dialect]
I had not included SQLMX hibernate jar in project.
It worked after I included that jar in my pom.

Spring Boot Test seems to be creating H2 Test DB different than what I would expect

So, I have a Test annotated with #DataJpaTest and #RunWith(SpringRunner.class), and an application.yml under /src/test/resources with this block (yes, indenting should be fine):
spring:
datasource:
url: jdbc:h2:mem:foobar;MODE=Mysql;MVCC=FALSE;
username: sa
password:
driver-class-name: org.h2.Driver
When I start the Test, I unexpectedly get these lines in the log:
2019-10-23 17:11:08.311 INFO 13468 --- [ main] beddedDataSourceBeanFactoryPostProcessor : Replacing 'dataSource' DataSource bean with embedded version
2019-10-23 17:11:08.801 INFO 13468 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:h2:mem:7855270f-61b7-4f37-8796-cbfeb8ad42ea;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
In particular this: Starting embedded database: url='jdbc:h2:mem:7855270f-61b7-4f37-8796-cbfeb8ad42ea;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false
Why is Spring boot starting a DB with a UUID-Generated DB and not taking the settings from spring.datasource.url?
The "productive" app takes the datasource settings fine from the file in /src/main/resources with same syntax without issues...
From the documentation of #DataJpaTest you can see that:
#DataJpaTest uses an embedded in-memory
database (replacing any explicit or usually auto-configured
DataSource). The #AutoConfigureTestDatabase annotation can be used to
override these settings.
So #DataJpaTest annotated with #AutoConfigureTestDatabase that causes TestDatabaseAutoConfiguration to create embedded datasource with hard-coded generateUniqueName(true):
TestDatabaseAutoConfiguration.java :
EmbeddedDatabase getEmbeddedDatabase() {
...
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.setType(connection.getType())
.build();
}
I think they do this to prevent DB name collisions and state mix between test runs.

Import schema.sql into a specificic H2 database with Spring Boot

I'm struggling to understand if I can import the data defined inside my schema.sql and data.sql into a specific H2 database.
I use Spring Boot 2.0.6 and this is the configuration inside my application.properties:
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:mem:assignment
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
And I correctly placed both schema.sql and data.sql inside the resources folder.
The application starts up correctly and imports the files:
2018-10-26 20:39:24.834 INFO 9448 --- [main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from URL [file:/C:/Users/Gabriele/code/java/assignment/target/classes/schema.sql]
2018-10-26 20:39:24.848 INFO 9448 --- [main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from URL [file:/C:/Users/Gabriele/code/java/assignment/target/classes/schema.sql] in 13 ms.
2018-10-26 20:39:24.850 INFO 9448 --- [main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from URL [file:/C:/Users/Gabriele/code/java/assignment/target/classes/data.sql]
2018-10-26 20:39:24.868 INFO 9448 --- [main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from URL [file:/C:/Users/Gabriele/code/java/assignment/target/classes/data.sql] in 18 ms.
But when I open the browser console, the assignment database is empty
while the test one is not.
What am I missing?

Resources