How to deploy on Heroku with Postgresql Database? - java

I have a simple rest app on spring. For deploy I've been created 2 profiles - dev & heroku. With dev profile it is all ok. But I can't deploy to Heroku:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project myProject: Error setting up or running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:postgres://aa2-22-222-222-222.aaaaaa-1.amazonaws.com:5432/aaaaaaaaa with driver org.postgresql.Driver. Possibly the wrong driver for the given database URL -> [Help 1]
I thought that the problem was in my old driver (locally I am using PG 9.4 but on Heroku is 9.6)
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
After update the issue was not resolved.
I tried to use connection strings directly and from System.env but the result was same.
How can I fix this?

Your database URL starts with jdbc:postgres:// but should be jdbc:postgresql://.
I recommend using the provided JDBC_DATABASE_URL environment variable instead of parsing the DATABASE_URL yourself:
https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-jdbc_database_url

Related

Build Java Application when using environment vars in application.properties

I have developed a Spring Boot Starter API. The API connects to MySql Database.
My application.properties:
# MySQL Connection
spring.datasource.url=jdbc:mysql://${MYSQL_URL}/${MYSQL_DB_NAME}
spring.datasource.username=${MYSQL_USER}
spring.datasource.password=${MYSQL_PWD}
During testing I inject the vars with my IDE (IntelliJ) in the Run -Configuration.
When I try to build a docker image using mvnw spring-boot:build-image I get an error, that I get an error com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure during test
I assume that maven tries to connect to the db and has no vars to replace the placeholders.
How can I build the image without including the connection-details in the image ??

java.sql.SQLException: Unknown system variable 'tx_isolation'

I am using play framework and I want to connect db, but I can't because I am getting following error:
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
Caused by: play.api.Configuration$$anon$1: Configuration error[Failed to initialize pool: Unknown system variable 'tx_isolation']
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Unknown system variable 'tx_isolation' java.sql.SQLException: Unknown system variable 'tx_isolation
I tried to find tx_isolation, but it doesn't exist:
mysql> show variables like 'tx_isolation';
Empty set (0.00 sec)
So what is and how can I find tx_isolation?
Sorry. this is my error code. and I use mysql 8.0.11. so i find 'transaction_isolation'
play.db {
config = "db"
default = "default"
}
db {
//TODO : 작업필요
default.driver = com.mysql.jdbc.Driver
default.url = "jdbc:mysql://127.0.0.1:3306/testPlayDB"
default.username = root
default.password = "321A#654"
}
Error cause Default.url = "jdbc:mysql://127.0.0.1:3306/testPlayDB"
i use Scala, playframework and StackOverflow first time...
Thank you.
If you are using MYSQL8, try to show variables like 'transaction_isolation'.
Mysql8 has renamed tx_isolation to transaction_isolation.
I had a same problem. I upgraded my MySql Connector and solved my issue. try to use version 8 , like this:
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
You have a mismatch between client lib version and server version.
Here are the version numbers where things change:
mysql-connector-java-8.0.8 release notes
Important Change: Following the changes in MySQL Server 8.0.3, the system variables tx_isolation and tx_read_only have been replaced with transaction_isolation and transaction_read_only in the code of Connector/J. Users should update Connector/J to this latest release in order to connect to MySQL 8.0.3. They should also make the same adjustments to their own applications if they use the old variables in their codes. (Bug #26440544)
mysql server 5.7.20 release notes
Previously, the --transaction-isolation and --transaction-read-only server startup options corresponded to the tx_isolation and tx_read_only system variables. For better name correspondence between startup option and system variable names, transaction_isolation and transaction_read_only have been created as aliases for tx_isolation and tx_read_only. The tx_isolation and tx_read_only variables are now deprecated and will be removed in MySQL 8.0. Applications should be adjusted to use transaction_isolation and transaction_read_only instead.
mysql server 8.0.3 release notes
The deprecated tx_isolation and tx_read_only system variables have been removed. Use transaction_isolation and transaction_read_only instead.
I was also getting the same error (when I am using the mysql6 database in mysql5 it was working fine) then I changed my connector jar from mysql-connector-java-5.1.46.jar to mysql.jar then the problem gone.

org.apache.hive.service.cli.HiveSQLException: java.lang.NoClassDefFoundError: org/apache/hadoop/ipc/CallerContext$Builder

I am trying to connect my hive jdbc client to hiveserver2.
i am using following maven
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>1.2.1000.2.4.2.12-1</version>
</dependency>
hiveserver2.start() started my hiveserver2.
but when i start my jdbc client with followin code :
val con: Connection = DriverManager
.getConnection("jdbc:hive2://localhost:10000/default", "", "")
val stmt: Statement = con.createStatement
stmt.execute("create table if not exists student (id int))
it gives me following exception :
org.apache.hive.service.cli.HiveSQLException:
java.lang.NoClassDefFoundError:
org/apache/hadoop/ipc/CallerContext$Builder at
org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:256) at
org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:242) at
org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:254)
Can anybody either help me to identify the reason of this or solution please.
Thanks in advance.
This could happen due to multiple reason:-
Either the corresponding jar wont be available which is the
hivejdbcdriver jar with the right version eg: "hive-jdbc-1.2.1.jar"
or sometimes you may to use
"hive-jdbc-1.2.1-standalone.jar"(depending upon on how your usecase
is) in the libraries folder or .m2 repository.
Or,it could also
be the jar may not be added in your classpath(add an entry for this
jar in your .classpath file), depending upon how your application is
built.

websocket code not working on Prod Tomcat Server - 404 Error

I am trying to run my first websocket app and refered this link to get some sample code . I simply created CustomEndPoint , WSClient class , html file and then ran it on netbeans IDE and it was working like a charm.
I tried to deploy it on tomcat server whose url is accessible using https by changing ws:// with wss:// and it worked on my dev environment but when I deployed the same code on Production env its throwing below error in console:
WebSocket connection to 'wss://xxxxxx-xxx.xxxx.com/websoc/ratesrv' failed: Error during WebSocket handshake: Unexpected response code: 404
For dev environment I below WS call is working :
wsocket = new WebSocket("wss://dev_ip:8443/websoc/ratesrv");
For Prod I am using(note the .com in url):
wss://xxxxx-xxxxx.xx.com/websoc/ratesrv
Do I need to explicitly provide the port number as well in PROD ?
Does your Tomcat version includes Websockets Runtime?
If it does you must delete all the Websockets dependencies from your WAR. Ensure that you call mvn clean after change scope to provided.
If not, you should include it. If you want to use Tyrus just put
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-servlet</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>1.12</version>
</dependency>
And check that that there are no errors in the Tomcat console when deploy.
Try to use the latest version of tomcat.
tomcat8.5.20 worked for me.

How can connect mysql to spring roo?

Spring-roo can't be connect to MySQL
when i execute command database reverse engineer --schema test --package then it give error:
Could not initialize class com.mysql.jdbc.Connection...
Image of error:
You need 2 things:
Configure connection info in project in src/main/resources/META-INF/spring/database.properties file. Spring Roo uses it to connect DB.
Make JDBC driver accessible by Spring Roo installing it in OSGi environ ( see manual section about it )
Good luck!

Categories