Heroku keeps on using Postgres instead of MySQL - java

I have a Java application that uses Hibernate. It's configured to write to a MySQL db. I can say that I configured it correctly because when I run it on my local machine (on Tomcat and Jetty), tables are created in my local db.
However, when I deploy it to Heroku, the tables are not created. Heroku logs:
Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'po
stgres://zzz:zzz#ec2-111-11-111-11.compute-1.a
mazonaws.com:5432/zzz'
Logs
Why is Heroku connecting to this db instead of using my configurations?
Additional info: App is deployed. It's just that the db tables are not created.

It looks like you're trying to establish a MySQL connection to a Postgres database. Either use a Postgres driver instead, or use a MySQL database.
Look here for MySQL databases: https://addons.heroku.com
PS. I'm guessing you used the default Heroku Postgres database - which populates DATABASE_URL with a Heroku Postgres Starter Tier database.

You need to point the DATABASE_URL variable to mysql database.
heroku config:set DATABASE_URL=mysql://xxxxxx

Related

Cannot connect to database through Intellij's Data Sources and Drivers

I have a problem with displaying my databse structure through Intellij's Data Sources and Drivers page. I can connect to my database which is hosted on a redhat server through using application.properties of my spring project:
spring.datasource.url=jdbc:postgresql://192.168.0.38:5432/cms_database
which works fine. Although, whenever I try to use Intellij's Data Sources and Drivers page I get an Error Message:
[3D000] FATAL: database "cms_database" does not exist.
I can test to connect to database "postgres" which returns a Connection:
DBMS: PostgreSQL (ver. 13.0) Case sensitivity: plain=lower,
delimited=exact Driver: PostgreSQL JDBC Driver (ver. 42.2.5, JDBC4.2)
Ping: 16 ms SSL: no
Any help would be appreciated. If you need any extra info I would be happy to post!
Try to connect with settings from this example
I think you will set hostname wrongly

Not able to connect to Postgres server via java application

In one of my project, we are trying to connect to Postgres server via Java application. It gives an error when try to open connection. Stack trace is below -
{"timestamp":"2016-03-17T06:57:18.853Z",
"level":"ERROR",
"thread":"main",
"logger":"com.abc.messaging.status.configuration.ValidateDatabaseConfiguration",
"message":"Failed to initialize data source: \n
### Error opening session. Cause: java.lang.NullPointerException\n
### Cause: java.lang.NullPointerException","context":"default"}
While we have tried following -
Ping db server from application server - it's successful
Telnet db server and port (from app server)- it's also successful
We also tried a simple python script that connects to postgre server. It also connects to db successfully.
We then moved back to our staging server and tried to connect production db server from there. This is also done successfully.
We tried connecting staging db server from production app server, which also we COULDN'T.
We are assuming that we don't have any issue in our application. This is because, from staging server, application can connect to both staging db and production db. There by, it must be some application server issue or something.
PostgreSQL version - Production - 9.4.5 Staging - 9.4.4
Java version - 1.8.31
Any kind of help would be much appreciated.
Thanks in advance.

How to export MySQL workbench database for Java application runs in other computers?

I developed a Java application connecting to MySQL database through a localhost connection.
Class.forName("com.mysql.jdbc.Driver");
Connection conexao = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/bd_sensores", "root", "rootadmin");
I want to run the application on other computers. To do that I need to export the database, and the information already recorded. I think I need to create an installer and install it on other computers, but I need to change local and type of database.
You could have a properties file that has the following properties:
driver class name
Database Host
Database Port
as well as username.
Read the db configurations from this properties file and then load the driver and prepare your jdbc url.
Also, you can export your database through mysql workbench to a .sql file that will create a db script to run on another database. Use 'Manage Export / Import' functionality of workbench under 'Server Administration'

Cannot connect to heroku postgres database using Netbeans

I am trying to connect to a database hosted in https://postgres.heroku.com/databases using Netbeans (build-in) Services/Databases. I am getting this error
Cannot establish a connection to jdbc:postgresql://ec2-xx-xxx-xxx-xxx.compute-1.am
I tried this with no issues:
1. Netbeans connecting to a local postgres database.
2. Using PgAdmin III connecting to heroku postgres databases.
I tried downloading the latest postgres driver and use it in netbeans to create connection but the same error.
Thanks in advance!
When connecting outside of Heroku (e.g. locally), add this to the end of your JDBC connection URL:
?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

How to get all the tables which I created using hsqldb runserver in standlone mode

I created the jdbc connection successfully for hsqldb in stanlone mode.I found where the new database is created.Using the path of newly created database in runserver ,I created some tables.But when I tried to get those table using jdbc connection,I could not get those table.
connection url is:"jdbc:hsqldb:file:databasename;ifexist=true","SA",""
for getting tables I m using the following query.
"select table_name from information_schema.system_tables where table_type='table'";
I am using hsqldb 2.2.7.
You seem to be trying to access the database simultaneously via Server and in-process. This is not possible. After each type of access, you need to shutdown the database before you connect to it via the alternative type of access. Therefore shutdown the Server once you have created the tables, then connect to the database in-process.
It is easier to access the database via Server only, and avoid such problems. Please also upgrade to version 2.2.8 to avoid a bug which may affect a database that has not been shutdown properly.

Categories

Resources