AWS RDS Proxy Connection from Java Spring Boot - java

We are using Java Spring Boot 2.3 alongside Postgresql as our database.
For better availability, we want to implement Multi A-Z and RDS Proxy for Postgresql.
In application.properties file, we are using the following properties for normal connection to the database and all works fine
spring.datasource.url=jdbc:postgresql://zzzz.us-east-1.rds.amazonaws.com:5432/postgres
spring.datasource.username=xxx
spring.datasource.password=yyy
When using RDS Proxy, i am trying to use same properties, but instead of the DB URL, i am using the endpoint of the RDS Proxy
spring.datasource.url=jdbc:postgresql://rds-proxy-endpoint.us-east-1.rds.amazonaws.com:5432/postgres
spring.datasource.username=xxx
spring.datasource.password=yyy
For testing purposes, RDS Proxy Security group is open and my machine has access to it, but still it wont let me connect, here is the error
24832 [task-1] ERROR com.zaxxer.hikari.pool.HikariPool --- HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
Am i missing something?
Thanks a lot in advance

Related

No suitable driver found for jdbc:postgresql://localhost:5432/postgres

I tried several tutorials that I could get my hands on, but all of them lead to the same error:
18:28:24,583 INFO [stdout] (default task-1) Database error :No suitable driver found for JDBC:postgresql://localhost:5432/postgres
I have configured the connection following this tutorial: HOW TO SETUP POSTGRESQL DATASOURCE WITH WILDFLY
and tried several ways to fix the problem. I have tried both the management console and the configuration file. The most common solution was trying to add the postgresql-42.2.24.jar to the project structures in modules, but that doesn't solve it. I have created a new simple Java project where I am just trying to connect to the database and it works (I used the same credentials in both places), but when I'm trying to link the server with the DB it's like it doesn't see the driver... When adding a Datasource from Intellij it works perfectly fine (it sees the tables, I can run queries and everything), but I can't get the connection with the server to work.
I'm using Wildfly 24.0.1 Final and Java 8.
Change JDBC to jdbc, it's case-sensitive.

SAP DBTech JDBC: [4321]: only secure connections are allowed

I am unable to create a connection with SAP Cloud Foundry HANA service from my Spring boot app. I have given JPA properties values as the information is provided in HANA HDI service binding in SCP CF but getting following error from my Sample Spring boot:
SAP DBTech JDBC: [4321]: only secure connections are allowed"
SAP CF HANA service is enforcing security is there any standard way to make connection with Spring boot to SAP HANA CF service?
Just to add connectivity is not working when making a connection in Springboot app via application.yml file by setting JPA properties, but was able to make a connection in a servlet using connection object by looking up the driver class manually via code.
How I can make a successful connection via JPA properties in application.yml file ?
try this for your data source url in application.yml:
jdbc:sap://{host}:{port}?encrypt=true&validateCertificate=false&currentschema={schema}
I have run into the exact same error.
Check your URL. In my case the URL looked similar to this one:
jdbc:sap://<host>:<port>?encrypt=true\u0026validateCertificate=true\u0026currentschema=D006A421632F47ED8A2C9346D28B67C2
Note the two occurrences of \u0026 escape sequences in the URL.
These should be & instead.
Once I changed them to & chars, it worked.
As previous answers noted, encrypt=true needs to be in the URL - but it won't be found if the & character is escaped.
If the URL contains the escape sequences, I would say it qualifies as a SAP HANA bug. Also, the error message is not really helping much. A message of Could not find encrypt=true in URL. Only secure connections are allowed! would have helped finding this more easily.
Issue seems to be known to SAP:
https://github.com/SAP/spring-cloud-sap/issues/8
There is at least a workaround listed on the end of the page, which might help.

How to handle re-connects to the DB with ActiveJDBC

I've a Spring Boot Java application in production that uses ActiveJDBC to access a MariaDB database.
If at launch the application boots before the db server, of if the db server crashes and restarts, the apps doesn't re-estabilish the connection with the db.
ActiveJDBC is on version 1.4.13 and if possible I'd prefer not upgrading it, to avoid possible breakages. The db parameters are configured using the database.properties file and typically the usage pattern is:
try {
Base.open();
...
} finally {
Base.close();
}
Is there a way to circumvent this problem, without monitoring and relaunching the application? Maybe using connection pools? If this is the case, are there any docs or examples?
If you are using a direct JDBC connection in your database.properties file, a new connection will be open every time you execute Base.open(). This means that any old connection that is broken is not relevant anymore. If you use a JDNI pool such as:
production.jndi=java:comp/env/jdbc/acme
then you want to configure your containers' pool to ensure that every connection served from the pool is valid just before the pool serves the connection to your app. It is up to the implementation and documentation of your container/pool how to do that.
In any case, I do not think you are going to have issues.

Prevent Spring Boot startup failure on couchbase connection error

Using a combination of Spring Boot 1.4.1.Release and Spring Data Couchbase 2.1.3.RELEASE, is there a way to prevent application startup failure if it cannot connect to couchbase?
Current behavior: Application cannot connect to couchbase on startup and exits.
The goal: Application would continue to start even though it cannot connect to Couchbase, use the timeout configurations in CouchbaseEnvironment, and continually try to connect in the background.
In Spring Boot, we can configure Spring JDBC to ignore failure on startup with spring.datasource.continue-on-error=true. Any chance something like that coupled with a retry on failure exists in Spring Data Couchbase?
You can configure CouchbaseEnvironment by overriding getCouchbaseEnvironment using JavaConfig and try increasing the connect timeout. Is there a specific connection failure you are running into?
There isn't continue-on-error property for spring-data-couchbase. This property is available on Spring Boot for relational JDBC and it is useful to ignore initialize failures such as failing to create tables and loading into data sources using scripts.

How to make J2EE weblogic application resilient to database problems

I have a Web application running on Oracle Weblogic Server 11g.
It uses a datasource defined in the application server to connect to the Oracle Database (11g too), its class is
oracle.jdbc.xa.client.OracleXADataSource
If for some reason the database becomes not present and then comes
backs, the application is running ok (it gets exceptions while trying
to access the db but this is fine and then can again get some new
connections when the db comes back)
However, if the database is down during weblogic server startup,
the datasource is not deployed on the server and the application
throws an exception because it has not any datasource available, the
deployment is marked as failed and of course nothing does repair this
automatically.
Is there a way to make the datasource be deployed even if the database is not present during server startup ? (such that the application becomes usable when the database is back)
Why do you want to deploy an application without a valid datasource?
You could possibly fake the datasource (create a dummy datasource with the same JNDI name) and assuming that the application does not validate datasource schema at startup you will get a semi-functional running application (which will fail with the first DB interaction).
When the real datasource is up and running you won't be able to switch to it. You will still have to restart the application server.
Update:
According to the J2EE spec (1.5 version) resources are binded during the deployment process. I believe that it is possible to implement a custom Factory that will return dummy / active datasource. Does it worth the effort to implement? ;)
EE.5.6.2 Deployer’s Responsibilities
Bind the resource manager connection factory reference to a resource manager connection factory that exists in the operational environment. The Deployer may use, for example, the JNDI LinkRef mechanism to create a symbolic link to the actual JNDI name of the resource manager connection factory. The re- source manager connection factory type must be compatible with the type de- clared in the res-type element.
The option you are looking for is "Connection Creation Retries", check this link
"If set and if the database is unavailable when the data source is created, WebLogic Server attempts to create connections in the pool again after the number of seconds you specify, and will continue to attempt to create the connections until it succeeds. This option applies to connections created when the data source is created at server startup ..."
set "Initial Capacity" http://docs.oracle.com/cd/E14571_01/web.1111/e13814/jdbc_tuning.htm#i1028616 to 0: weblogic on startup will not attempt to create any connection, and will not fail if the DB is not available.

Categories