Unable to connect non stop SQL from Spring boot applivcation - spring-boot

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.

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

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.

Spring boot 2.1.0 Hikari CP bad password

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.

Spring Boot Project Jar file not reading File placed on classpath

I am connecting my Spring Boot app with Google Cloud Sql and it got connected by placing Credential File in src/main/resources but Issue comes when I try to run the Jar File - [FileNotFound]
:: Spring Boot :: (v2.0.3.RELEASE)
application.properties-
spring.cloud.gcp.credentials.location=classpath:ArpanShoppingApp-863d536d1f93.json
and running jar file gives exception
java -jar CloudSQLConnect-1.0.jar
Exception-
2018-06-22 10:46:38.393 INFO 1172 --- [ main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Default MYSQL JdbcUrl provider. Connecting to jdbc:mysql://google/google_sql?cloudSqlInstance=mindful-highway-207309:asia-south1:shopping-db&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false with driver com.mysql.jdbc.Driver
2018-06-22 10:46:38.401 INFO 1172 --- [ main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Error reading Cloud SQL credentials file.
java.io.FileNotFoundException: class path resource [ArpanShoppingApp-863d536d1f93.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/arpan/Documents/workspace-sts-3.8.4.RELEASE/CloudSQLConnect/target/CloudSQLConnect-1.0.jar!/BOOT-INF/classes!/ArpanShoppingApp-863d536d1f93.json
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:133) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.setCredentialsProperty(GcpCloudSqlAutoConfiguration.java:167) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.defaultJdbcInfoProvider(GcpCloudSqlAutoConfiguration.java:107) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration$$EnhancerBySpringCGLIB$$edf77794.CGLIB$defaultJdbcInfoProvider$1(<generated>) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
This appears to be a limitation of spring-cloud-gcp. It seems like credential files must be on the filesystem and cannot be package into a jar. The latest code has a better error message than the M1 version that you're using.

Using HikariCP as connection pool with GemfireXD in a Spring boot application throws ClassCastException

I am trying to use HikariCP with Gemfire XD in a Spring boot application.I am getting below ClassCastException:`
10:29:04.757 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Started.
10:29:04.791 [main] WARN c.z.hikari.util.DriverDataSource - Registered driver with driverClassName=com.pivotal.gemfirexd.internal.jdbc.ClientConnectionPoolDataSource was not found, trying direct instantiation.
10:29:04.794 [main] WARN c.z.hikari.util.DriverDataSource - Failed to create instance of driver class com.pivotal.gemfirexd.internal.jdbc.ClientConnectionPoolDataSource, trying jdbcUrl resolution
java.lang.ClassCastException: com.pivotal.gemfirexd.internal.jdbc.ClientConnectionPoolDataSource cannot be cast to java.sql.Driver
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:71)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:298)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:91)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:101)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:658)
I have specified below configurations in application.properties file:
spring.datasource.url=jdbc:gemfirexd://192.168.162.141:1527/
spring.datasource.username=APP
spring.datasource.password=APP
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.driver-class-name=com.pivotal.gemfirexd.internal.jdbc.ClientConnectionPoolDataSource
spring.datasource.schema=APP
spring.datasource.transaction-isolation=0
spring.datasource.auto-commit=true`**
And as per the BlogPost I have tried changing to
spring.datasource.driver-class-name=com.pivotal.gemfirexd.internal.jdbc.ClientDataSource
But still it does not work and throws same exception.
Gemfire XD Version:1.4.1
HikariCP Version:2.4.6
Spring boot Version:1.3.5
Spring JDBC version:4.2.6
Java Version :1.7

Resources