HikariCP Postgresql Driver Claims to not accept JDBC URL - java

I've pushed my application to cloudfoundry. However every time I connect to my postgresql/elephant sql I received this error
Driver org.postgresql.Driver claims to not accept JDBC URL jdbc:postgres://cwkqmdql:SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX#pellefant.db.elephantsql.com:5432/cwkqmdql/
Is there anything I've missed?

There are a few issues with that URL and a latest PSQL driver may complain.
jdbc:postgres: should be replaced with jdbc:postgresql:
Do not use jdbc:postgresql://<username>:<passwor>..., user parameters instead: jdbc:postgresql://<host>:<port>/<dbname>?user=<username>&password=<password>
In some cases you have to force SSL connection by adding sslmode=require parameter
So your URL should be:
jdbc:postgresql://#pellefant.db.elephantsql.com:5432/cwkqmdql?user=cwkqmdql&password=SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX
or
jdbc:postgresql://#pellefant.db.elephantsql.com:5432/cwkqmdql?user=cwkqmdql&password=SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX&sslmode=require
I hope that will help.

In my case it was defining the property in double quotes in the java.properties file
by changing
jdbcUrl="url"
to
jdbcUrl=url
it works again

The issue I had was that I had given double quotes for the datasource url in the properties file.
What I had given :
spring.datasource.url="jdbc:postgresql://localhost:5432/postgres"
The correct way to give the url is :
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres

also had this error, but realized it was because i had typed
postgressql
instead of
postgresql in my url

I had the same issue with h2 DB in WebFlux. The issue was with spring.datasource.driver
Not working
spring.datasource.driver=org.h2.Driver
Working
spring.datasource.driver-class-name=org.h2.Driver

I was having the same error until I realize that I did not set my profile to active in the application.properties class.
spring.profiles.active = dev

Replace
postgresql://localhost/db_name
with
jdbc:postgresql://localhost/db_name

In my case, two configuration files are in different format:
application.properties in src/main/resources
application.yml in src/test/resources
After changing application.yml to application.properties in src/test/resources, the issue was fixed.

Related

Spring Error: Failed to determine suitable jdbc url

I'm trying to learn Spring and following a guy's instructions on YouTube. At first, he only initialized the Spring project and wrote configurations which I copied and created the database called employeemanager. In short, I did exactly the same things with him but I get this error when I try to run the program:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc URL
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
I am using MySQL and JPA. This is my configuration:
spring.datasoruce.url=jdbc:mysql://localhost:3306/employeemanager
spring.datasource.username=root
spring.datasource.password=2525
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
I found a solution online which is writing:
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) instead of #SpringBootApplication
This solved the problem at first, however, some people mentioned that this is not a proper solution. So I have 2 questions:
What is the reason for this problem and how can I fix it?
What exactly the solution I mentioned is doing in simple words?
Thank you.
It seems you have misspelt the property spring.datasoruce.url incorrectly. The spelling of datasource is incorrect. Can you try with spring.datasource.url.

Spring ignores Mongo settings in application.properties

I am trying to learn MongoDB with Spring. When I try to write to the db it works but everything goes to the test database. Here is how my application.properties file looks like:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.username=
spring.data.mongodb.password=
spring.data.mongodb.database=pets
The records are supposed to go to the database pets, but they all go to test. Any idea why? I have no other configurations. Even when I comment out all those settings, it still works and writes to test, which makes me think that they are just being ignored. I have no password and username set up.
Thanks
For some reason, I solved it by defining a MongoConfig and setting the database name there. Apparently, it is deprecated, but it works...

Spring Boot MSSQL Kerberos Authentication

Currently in my spring boot application.properties file, I am specifying following lines to connect to MSSql server.
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=springbootd
spring.datasource.username=sa
spring.datasource.password=Projects#123
Instead of giving username and password, I want to authenticate user using kerberos, what all changes I will have to make.
I tried searching in the JPA official documentation but could not find any. Leads here are appreciated.
Basically, you need to set up your krb5.conf file properly. You can verify that configuration via the following command and entering your password:
kinit <user-name>
Additionally, make sure you have a JDBC URL like:
jdbc:sqlserver://servername=server_name;integratedSecurity=true;authenticationScheme=JavaKerberos;userName=user#REALM;password=****
See Microsoft JDBC driver documentation for details.
EDIT:
Forgot to mention the startup arguments. Add the following JVM argument:
-Djava.security.krb5.conf=<PATH_TO>/krb5.conf
I believe this is not neccessary if you use the default krb5.conf but not entirely sure.

How to set "max_allowed_packet" property from spring application.yml

I need to change "max_allowed_packet" property for mySQL data base from SPRING property file (application.yml). I found some topics about that, like this.
They proposed to use mySQL command line:
$>mysql --max_allowed_packet={some_value}
But maybe someone know new solution for this task? It would be great to have this ability.
You cannot change --max_allowed_packet property from spring application.yml file, because this is a mysql server property. Therefore you should set this property when you start the mysql server.
You could add it in my.cnf, check this answer

Spring Boot - How to set the default schema for PostgreSQL?

What I am currently doing in my application.properties file is:
spring.datasource.url=jdbc:postgresql://localhost:5432/myDB?currentSchema=mySchema
Isn't there another property for this? Since it looks hacky and according to a post (still finding the link sorry, will update later), it is only applicable to PostgreSQL 9.4.
Since this is quite old and has no proper answer yet, the right property to set is the following:
spring.jpa.properties.hibernate.default_schema=yourschema
You can try setting the default schema for the jdbc user.
1)
ALTER USER user_name SET search_path to 'schema'
2) Did you try this property?
spring.datasource.schema
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html
With SpringBoot 2.5.5 the only thing that work for me:
aplication.properties
spring.datasource.hikari.schema=my_schema
aplication.yml version:
spring:
datasource:
hikari:
schema: my_schema

Categories

Resources