Connection error while creating a basic SpringBoot app with MySQL - java

So i'm trying to create basic SpringBoot app with DB connectivity and here is my application.properties
spring.datasource.url=jdbc:mysql://sql.somehost.net:3306/thisismydbname
spring.datasource.username=sql9XXXXXX
spring.datasource.password=XXXXXXXX
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 created a very basic SpringBoot app with Spring Data JPA and maybe Spring Web dependencies.
When I try to boot up the app, I get the following error
java.sql.SQLException: Access denied for user 'sql9XXXXXX'#'ip6x-xxx-xx-xxx.dc.dc.cox.net' (using password: YES)
When I try to connect to MySQL using MySQL Workbench externally this works fine. Also, it's very weird why it's trying to use my ISP Cox in the connection. I don't know how it picked up my ISP details. I do have the somehost.net where my MySQL is hosted.

Related

Spring boot web application not working with oracle wallet Connection

In my spring boot I'm making a connection to Oracle Database using Oracle wallet. But while connecting to the database getting invalid username/ password error.
enter image description here
defined data source information inside application.properties file:
spring.datasource.url=jdbc:oracle:thin:#name_in_tnsnames?TNS_ADMIN=C:/path/to/oracle/wallet

The easiest Junit test for connection to database in spring boot application

I started to write application with friend and I would like to write a simple test for database connection. He is owner of server so test will be red now of course but when he set up database and change url, password and username it should become green. I think if there is some simpler test than writing controller/service/repository and try to do some operation on it to check database connection.
All we have for now is spring boot app generated by spring initilizr and application.properties:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=dummy_url
spring.datasource.username=dummy_username
spring.datasource.password=dummy_pass
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Is it testable in this state or I must create fully operational endpoint and test it?
try looking into JHipster: https://www.jhipster.tech/
normally you can use a memory database like h2 for local and test environment ;)

AWS RDS Proxy Connection from Java Spring Boot

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

Spring Boot Framework doesn't initialize Database on Startup

I have a problem with the Spring Framework. It doesn't create the database automatically on startup. I read the HowTo-Guides of Spring on how to initialize the database and followed these steps, but it doesn't work. I also searched around the web for similar problems, but I didn't find anything which could help me.
Error description:
On startup of the Server, I get an Errormessage:
FATAL: Datenbank »money_man_api_db« existiert nicht (German)
FATAL: Database »money_man_api_db« does not exist (English translation)
My configuration:
application.properties:
server.port=3000
# Basic Connection Configuration
spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.maximum-pool-size=5
# PostgreSQL Configuration
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.initialization-mode=always
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/money_man_api_db
spring.datasource.username=postgres
spring.datasource.password=admin
Why doesn't the database get initialized? Did I forget something?
First you should create a database, later on you can connect to this database.
The title is misleading because Hibernate will not create a database, but will create the tables in this database. Hibernate is an ORM, it will create compatible SQL queries to interact with the database.
It's a layer between your OO code and the database, that takes care of complexity of creating SQL queries and mapping them to your code.
More info can be found here: https://hibernate.org/orm/

Spring database initialization works only after app reboot

I am finishing a training project with Rest api in Java,
with springboot and a postgresql database.
Im trying to initialize the database on startup, with schema.sql, and data.sql.
The creation and the data injections works fine when i look directly in the db through PgAdmin, with that configuration file.
spring.datasource.url = jdbc:postgresql://localhost:5432/db_test
spring.datasource.username = adm_library
spring.datasource.password = admin
spring.datasource.driver-class-name = org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect
#hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.datasource.initialization-mode=always
#spring.jpa.hibernate.ddl-auto = none
But, if i try to use the application straight away, i'm getting
org.postgresql.util.PSQLException: ERREUR: the relation « book » doesn't exists
Here the entity causing error is "book" cause i try to retrieve books but it can be "users" if i try to retrieve users etc...
I found a way of making it work by rebooting the app without
spring.datasource.initialization-mode=always
And then it's ok.
Any explanation on this behaviour ?
Thanks !
Spring Boot automatically creates the schema of an embedded DataSource. This behavior can be customized by using the spring.datasource.initialization-mode property.
For instance, if you want to always initialize the DataSource regardless of its type:
spring.datasource.initialization-mode=always
More details can be checked in the java doc at Java-Doc and Spring Documentation.

Categories