Cant connect to database - java

I'm trying to connect to my database when I start my server in drop wizard. But I get the following error when I try to start the server
org.hibernate.engine.jdbc.internal.JdbcServicesImpl: HHH000342:
Could not obtain connection to query metadata :
Driver:org.h2.Driver#7ed6a46e returned null for
URL:jdbc:mysql://localhost:3306/testDatabase
Here is the code for my .yml (yaml) file
# Database settings.
database:
# the name of your JDBC driver
driverClass: org.h2.Driver
# the username
user: root
# the password
password: superSecretPassword
# the JDBC URL
url: jdbc:mysql://localhost:3306/testDatabase
server:
type: simple
connector:
type: http
port: 8080
What could be the problem here?

You use a wrong JDBC- Driver class: org.h2.Driver You have to use a mysql driver like com.mysql.jdbc.Driver

Related

MySql error "Cannot create PoolableConnectionFactory (Could not create connection to database server.)" while connecting with azkaban?

I am trying to connect Azkaban ( A job scheduler for hadoop) with my local mysql. The configiration file of azkaban looks like:
database.type=mysql
mysql.port=3306
mysql.host=localhost
mysql.database=azkaban
#Changed by Prakhar for azkaban , Azkaban
mysql.user=root
mysql.password= [ Password of mysql ]
My MySql has a database named "azkaban" and i am able to login mysql using command:
./mysql -u root -p
Also mysql is working on port 3306, which i have verified.
Still i am unable to connect to mysql. The logs of azkaban looks like this:
2020/04/11 22:38:05.584 +0530 ERROR [MySQLDataSource] [Azkaban] Failed to find write-enabled DB connection. Wait 15 seconds and retry. No.Attempt = 1
java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2294)
at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2039)
at azkaban.db.MySQLDataSource.getConnection(MySQLDataSource.java:76)
at org.apache.commons.dbutils.AbstractQueryRunner.prepareConnection(AbstractQueryRunner.java:175)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:286)
at azkaban.db.DatabaseOperator.query(DatabaseOperator.java:68)
at azkaban.executor.ExecutorDao.fetchActiveExecutors(ExecutorDao.java:53)
at azkaban.executor.JdbcExecutorLoader.fetchActiveExecutors(JdbcExecutorLoader.java:266)
at azkaban.executor.ExecutorManager.setupExecutors(ExecutorManager.java:223)
at azkaban.executor.ExecutorManager.<init>(ExecutorManager.java:131)
at azkaban.executor.ExecutorManager$$FastClassByGuice$$e1c1dfed.newInstance(<generated>)
at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
at
Few pointers that might help you to resolve the issue.
Please check the version of MySQL installed vs the MySQL client mentioned in the Gradle file used to build Azkaban
Preferably use MySQL 5.x version
Make sure to install the compatible client version
Also, create the Mysql tables in the database before starting the web executor

unable to configure url,username,password in pivotal cloud foundry

I had configured mssql as a user provided service in pcf. had created a java application with springboot and flywaydb for migration. When i try to deploy my java application into pcf it gives me the error "Caused by: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!". Had bind my app to the mssql service and restarted the application in pcf, but still the same error.
application.properties
spring.datasource.url=${vcap.services.db.credentials.jdbcUrl}
spring.datasource.username=${vcap.services.db.credentials.username}
spring.datasource.password=${vcap.services.db.credentials.password}
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
mssql configuration in pcf
uri : sqlserver://xxx:yyy#zzz:1433/db
username : xxx
password : yyy
expected : server should start without any issues and the tables should be created as mentioned in the migration sql file
actual : error "Caused by: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!".

Running Custom Textsecure (signal) Server Locally on Windows 10

I need to remove error in setting up of Signal server on my desktop ___Topic - Setting up of Signal Server on windows.
Post followed -
Run custom TextSecure (Signal) server
http://debabhishek.com/writes/Installing-and-Running-TextSecure-Signal-Server-on-Windows/
I am using ref .yml file template from github resources for signal.
When trying to - RUn
java -jar target/TextSecureServer-1.88.jar accountdb migrate config/textsecure.yml
I get error - >
io.dropwizard.configuration.ConfigurationParsingException:
config/textsecure.yml has an error: * Failed to parse configuration
at: turn.uris.[0]; Cannot deserialize instance of java.lang.String
out of START_OBJECT token at [Source: UNKNOWN; line: -1, column: -1]
(through reference chain:
org.whispersystems.textsecuregcm.WhisperServerConfiguration["turn"]->org.whispersystems.textsecuregcm.configuration.TurnConfiguration["uris"]->java.util.ArrayList[0])
at io.dropwizard.configuration.ConfigurationParsingException$Builder.build(ConfigurationParsingException.java:279)
at io
...
My textsecure.yml file is -
twilio: # Twilio gateway configuration
accountId: MYID
accountToken: MYTOKEN
numbers: # Numbers allocated in Twilio
-
+MYNO
messagingServicesId:
localDomain: http://localhost/
# Domain Twilio can connect back to for calls. Should be domain of your service.
push:
queueSize: 10000
# Size of push pending queue
turn: # TURN server configuration
secret: # TURN server secret
uris:
- stun: http://localhost:80
- stun: http://localhost:443
- turn: http://localhost:443?transport=udp
- turn: http://localturn4signal:80?transport=udp
cache: # Redis server configuration for cache cluster
url: redis://12.12.12.1:6379/1
replicaUrls: redis://12.12.12.1:6379/2
directory: # Redis server configuration for directory cluster
url: redis://12.12.12.1:6379/3
replicaUrls: redis://12.12.12.1:6379/4
messageCache: # Redis server configuration for message store cache
url: redis://12.12.12.1:6379/5
replicaUrls: redis://12.12.12.1:6379/6
messageStore: # Postgresql database configuration for message store
driverClass: org.postgresql.Driver
user: postgres
password: ""
url: "jdbc:postgresql://localhost:5432/messagedb"
attachments: # AWS S3 configuration
accessKey: MyKey
accessSecret: MySecret
bucket: MuBucket1
profiles: # AWS S3 configuration
accessKey: MYKEY2
accessSecret: MySectret2
bucket: MyBucket2
#region:
database: # Postgresql database configuration
driverClass: org.postgresql.Driver
user: "postgres"
password: ""
url: "jdbc:postgresql://localhost:5432/accountsdb"
apn: # Apple Push Notifications configuration
bundleId:
pushCertificate:
pushKey:
gcm: # GCM Configuration
senderId: MYID
apiKey: MYKEY
Can some one please help to remove the error
Remove the http:// and spaces.
You probably are looking for:
turn: # TURN server configuration
secret:
uris:
- stun:127.0.0.1:80
- stun:127.0.0.1:443
- turn:127.0.0.1:80?transport=udp
- turn:127.0.0.1:443?transport=udp
For more details, see the forum-thread: https://community.signalusers.org/t/seeting-up-of-new-signal-server-instance-on-windows-10/4032/4
turn: # TURN server configuration
secret: 121654fjdfgdyesdfgfhgh # TURN server secret
uris:
- stun:yourdomain:80 #fake
- stun:yourdomain.com:443 #fake
- turn:yourdomain:443?transport=udp #fake
- turn:etc.com:80?transport=udp #fake
This is the configuration working for me.

From Springboot app connect to mysql container

Hello guys !
It's my first so I will try to make the best that I can.
I want to create an app which is running with Springboot framework and I would like to connect it to a docker container which embeds MySQL (but the spring boot app is not running on docker)
So I have followed this post
I have made my docker-compose:
db:
image: mysql
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=users
volumes:
- ../data:/var/lib/mysql
and I run it with this command :
docker-compose run --service-ports db
All is fine, so now I change my application.properties on spring boot :
## Server Properties
server.port= 5000
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= jdbc:mysql://127.0.0.1:3306/users?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username= root
spring.datasource.password= secret
## Hibernate Properties
#The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto = update
## Hibernate Logging
logging.level.org.hibernate.SQL= DEBUG
## Jackson Properties
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
spring.jackson.time-zone= UTC
But When I run my app, I have this error :( :
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
I'm on MacOS...
I tried to follow callicoder's course ...
https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-app-part-1/
Thanks for your help :)
The problem is that the db container is not running on localhost but rather inside a mini Linux VM since you are on a MAC.
Thus to connect to the database you need to use the IP address of the machine where the container is running. To do that run the command docker-machine ip default. This will return the IP address which you would use in the connection url rather than localhost:
spring.datasource.url= jdbc:mysql://<docker-machine-ip>:3306/users?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false

Dropwizard Migrations: dump non public schema to the migrations.xml postgresql

As mentioned in dropwizard-migrations documentation, you can dump you existing schema to migrations.xml using command
java -jar hello-world.jar db dump helloworld.yml
But I am using postgresql which can have multiple schemas, so how can I configure my db to always get status/dump of the default schema i am woking on instead of public schema.
I tried changing the search_path for database but that doesn't worked out.
Liquibase has a defaultSchemaName property. I haven't used dropwizard myself but it seems they use JDBI and a yaml based config file for the db connection.
So, have you tried just putting the option defaultSchemaName into your service configuration file like this:
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: pg-user
# the password
password: iAMs00perSecrEET
# the JDBC URL
url: jdbc:postgresql://db.example.com/db-prod
# any properties specific to your JDBC driver:
properties:
charSet: UTF-8
defaultSchemaName: <yourSchemaName>
Jens was very close, you need to specify the currentSchema not defaultSchemaName property for the JDBC driver. like:
database:
driverClass: org.postgresql.Driver
# the other attributes
properties:
currentSchema: <yourSchemaName>

Categories