I am trying to connect the spring boot application I have created locally to an aws serverless aurora database.
I have added the maven dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
As well as created an application.properties file:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://myawsclusterlink:3306/mycluster
spring.datasource.username=myusername
spring.datasource.password=mypassword
spring.datasource.hikari.minimum-idle=0
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.max-lifetime=90000
spring.datasource.hikari.idle-timeout=90000
I have also created a VPC inbounds group for the db to allow incoming traffic from my IP address.
My Issue is that that when I run the app, my connection keeps failing with an error message:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I would like to know where is the problem. Is my url wrong? Have I not enabled something on aws? Is there something missing in my code?
Also, I don't really know how to test and see where the problem is coming from in this case.
Changing from serverless to provisioned aurora and enabling public access solved the issue
Related
I am trying to connect to my local MongoDB replica set (configured via Docker Compose) via an application running on Quarkus, however I am getting the following error as soon as I try to access the database via the application:
2022-01-24 14:51:03,170 ERROR [org.mon.dri.cluster] (cluster- ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo1:27017) Expecting replica set member, but found a STANDALONE. Removing mongo1:27017 from client view of cluster.
2022-01-24 14:51:03,177 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo3:27017) Expecting replica set member, but found a STANDALONE. Removing mongo3:27017 from client view of cluster.
2022-01-24 14:51:03,182 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo2:27017) Expecting replica set member, but found a STANDALONE. Removing mongo2:27017 from client view of cluster.
2022-01-24 14:51:08,179 ERROR [nl.rab.kno.int.LoggingInterceptor] (executor-thread-0) LoggingInterceptor.MethodCallEvent(className=nl.rabobank.knowledge.service.PreferencesService, methodName=getLanguagesForUser, result=EXCEPTION, exception=com.mongodb.MongoTimeoutException: Timed out after 5000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1#31e1baef. Client view of cluster state is {type=REPLICA_SET, servers=[])
For some reason it seems to identify my nodes as standalone, instead of replica set members, afterwhich they are getting removed from the client view of the cluster. I am wondering what goes wrong here?
This is the connection string that I am using in my Quarkus application:
quarkus:
mongodb:
connection-string: mongodb://mongo1:27021,mongo2:27022,mongo3:27023/database?replicaSet=dbrs
I simply followed this guide for setting up a replica set in MongoDB with Docker Compose: https://blog.tericcabrel.com/mongodb-replica-set-docker-compose/.
These are the dependencies used by my Quarkus application (version 2.6.2):
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
You have forgotten to tell your nodes that, they belong to a replica set!
You have two choices, command line:
mongod --replSet "rs0" --bind_ip localhost,<hostname(s)|ip address(es)>
or inside of config -file
replication:
replSetName: "rs0"
net:
bindIp: localhost,<hostname(s)|ip address(es)>
Check more information from here!
It looks like I found the problem. I managed to get rid of that specific error after removing Mongo on my local machine, resulting in only having Mongo as part of my containerised nodes.
However, I am running into another issue now for which I created this post: Connecting to containerised MongoDB replica set with Docker results in "Canonical address ... does not match server address.".
The best documentation I have been able to find about how to create a JDBC URL for an SQL Server instance within Cloud SQL is located here: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory
The only problem is, there is no example or instructions for creating the JDBC URL for SQL Server.
I have tried some obvious possible solutions, none of which have worked - for example:
jdbc:sqlserver:///<DATABASE_NAME>;socketFactory=com.google.cloud.sql.sqlserver.SocketFactory;cloudSqlInstance=<INSTANCE_CONNECTION_NAME>;user=<USER_NAME>;password=<PASSWORD>
I have a mysql server in the same project that I am able to connect to with no issue (after updating the jdbc Driver and JDBC URL). SQL Admin API is enabled and GOOGLE_APPLICATOIN_CREDENTIALS is pointing to the correct service account.
Relevant pom.xml
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>cloud-sql-connector-jdbc-sqlserver</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre8</version>
</dependency>
If i'm reading the git repo correctly it actually looks like JDBC support for SQL Server was just added in the 1.2.0 release - has anyone been able to get this to work?
https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/pull/263
Error I am receiving
ERROR: The TCP/IP connection to the host /<DATABASE_NAME>, port 1433 has failed. Error: "/<DATABASE_NAME>. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."
Thanks!
The root cause was that the version of SQLServerDriver I was using does not appear to compatible with com.google.cloud.sql.sqlserver.SocketFactory. I was able to switch to the net.sourceforge.jtds.jdbc.Driver which worked as expected. More info in this thread: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/373
I have setted up an Oracle cloud Autonomous transaction Processing (ATP) database, but when I am trying to connect it to my Java Spring boot application, it is throwing error:
java.sql.SQLRecoverableException: IO Error: An existing connection was forcibly closed by the remote host, Authentication lapse 0 ms."
I have correctly configured tnsnames.ora file and also sqlnet.ora file with proper location of credentials folder. But still getting above error.
My application.properties file is as below:
spring.datasource.url=jdbc:oracle:thin:#sampledb_high?TNS_ADMIN=E:\\Oracle cloud POC\\Wallet_sampleDB
spring.datasource.username=ADMIN
spring.datasource.password=********
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
Please let me know how to solve this.
Download the wallet from the UI
then unzip the wallet zip into a folder
for spring boot configuration
spring.datasource.url=jdbc:oracle:thin:#ddf9jcwvp9o3z7aa_high?TNS_ADMIN=/home/mintozzy/Downloads/Wallet_DDF9JCWVP9O3Z7AA
spring.datasource.username=READONLY_USER
spring.datasource.password=qw27dLDW4uDZf9D
You can see running spring boot petclinic example here for full properties
here you can see how to connect sql developer to cloud db.
I am developing a simple JAVA Time triggered Azure Function.
I am trying to connect to a Azure MySQL instance but I keep getting this error:
[Information] com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Here is the source code:
String url="jdbc:mysql://XXXX.mysql.database.azure.com:3306/DBNAME?useSSL=true&requireSSL=false";
connect = DriverManager.getConnection(url, "user#DBNAME", "passwd");
statement = connect.createStatement();
resultSet statement.executeQuery("select * from table1");
I am using the following library:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
Notes:
The program works fine on my local machine (i.e., after adding my IP address to the MySQL firewall, I can reach the DB from my machine);
I've already tried different mysql libraries: nothing changes;
Another Azure function implemented with NodeJS is able to reach the DB;
I tried to add the Function "ADDITIONAL OUTBOUND IP ADDRESSES" to the MySQL firewall: nothing changes.
Any ideas?
Thank you in advance.
5.1.31 MySQL-connector-java version Worked for me.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
Connecting MySQL Azure with Java
I am using a domain user account to connect to SQL server database and when I try to start my server I get the exception com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user error. I am using sqljdbc4-1.0.jar drivers.
The userid I am using is a service user id (a domain user id) which is different from the userid I am logged into windows. So I cannot use IntegratedSecurity option. my connection url looks like
jdbc:sqlserver://server;authentication=SqlPassword;userName=domain\username;password=mypassword;databaseName=mydatabase;
I even tried providing the username and password separately and even that also did not work. I searched a lot but could not find any relevant help. Please help.
I recently had the same problem with java app(Spring Boot) connecting with a domain user and wasting a few days doing it, but I managed, here's how I did it, hope it helps:
pom.xml:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
properties file:
jdbc:jtds:sqlserver://host:port;databaseName=dbname;instance=SQLDEV;domain=domainname.corp;user=userdb;password=p4ssw0rd;
example:
my file has too many options remove it if you don't use it
spring.application.name=app-name
spring.profiles.active=dev
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.url=jdbc:jtds:sqlserver://100.50.50.56/MinWeb;instance=SQLDEV;domain=domainname.corp;user=userdb;password=password;
spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1
spring.datasource.time-between-eviction-runs-millis=60000
spring.datasource.remove-abandoned=true
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.hbm2ddl.auto=none
Here are some links that I consulted:
Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC
Configure HikariCP in Spring Boot with JTDS
Create a jTDS connection string
T+