I have a legacy app that is currently working with Postgres9 that I have to migrate to postgres12.
I did the dump the old database and restored it to the new one without issues.
But when I tried to connect my legacy app with the new database the app never connects.
In the past, my POM was:
<!-- Postgresql Database Support -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
and now (after checking that the old version was not working I tried to did some update here):
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
In my properties I have:
jdbc.driver=org.postgresql.Driver
jdbc.url=jdbc:postgresql://XXXXXXXXXXXXXXXXXXXXXXxxxx:XXXX/db_name
jdbc.username=db_user
jdbc.password=xxxxx
Before I was using a postgres installed in a server, but now, I'm using a Database for postgres from IBM Cloud (I supossed this should not generate any issue). Similar to RDS from AWS.
So when I tried to run my app I got tomcat timeout. I increased the timeout to 120 but I'm still getting that error...
Exactly same configuration on Dbeaver works like a charm.
I tried with that version of the driver but same behavior (the one for org.postgres)
Related
I am using microsoft sql server,
If i open intellij, open new database connection in database tool window =>
and in advanced type i add:
The connection works. However now i want to connect to this ms sql server with spring jpa. So what i am using is:
spring.datasource.url=jdbc:jtds:sqlserver://<host>:<port>;instance=<instance>;domain=<domain>;useNTLMv2=true
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driverClassName=net.sourceforge.jtds.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
And it just says "login for user failed"
In my pom i am using:
<!-- jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.jpa.version}</version>
</dependency>
<dependency>
<groupId>jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2</version>
</dependency>
Why does it work with database tool window, but not with jpa?
Thanks for help!
Your are mixing JDBC driver connecting with sprig data JPA connection, for JPA proper connection you can change the drive class name to
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
Then the dialect can be
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
And finally add the proper url and remove JDBC driver relavent dependencies
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=<dbname>
Remaining properties will be same as your, see both examples in here .
I'm a beginner at java and i'm developing a big app the big issue is that i need a big database for which i should make a server side application(which i don't know how) to connect to Postgres. I did not find anything about making it and connecting it to PostgreSQL to Android Studio for instance.. I'm really confused and can't find anything about the topic. Excuse my bad English.
I recomend to see this example https://spring.io/guides/gs/accessing-data-mysql/
Mysql is being used, but you could simple change the "jdbc driver" to connect with PostgreSQL
First change driver in pom.xml
this
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
to
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
and then replace the url in src/main/resources/application.properties with the connection info of your postgres instance.
spring.datasource.url=jdbc:postgresql://host:port/database
also add this line to the properties:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
See https://github.com/spring-projects/spring-boot/issues/12007
On postgres user is a reserved keyword, so you have to change the name of the table that maps with User entity:
import javax.persistence.Table;
#Entity // This tells Hibernate to make a table out of this class
#Table(name = "users")
In this way you have the example working.
If not needed to do in Java, you can do it on other languages and frameworks, but the main idea would be to have an API and fetch or post data from/to.
I leave you some useful links to have more information
JDBC https://en.wikipedia.org/wiki/Java_Database_Connectivity
PostgreSQL JDBC Driver : https://github.com/pgjdbc/pgjdbc
ORM: https://en.wikipedia.org/wiki/Object-relational_mapping
Hibernate, a Java ORM http://hibernate.org/orm/
REST: https://spring.io/understanding/REST
The case is that I have launched both Spring Cloud Data Flow Server and Shell apps in my local machine, and they all used the H2 memory database to store the tasks and jobs defination.
When I deployed the application that Used a H2 as the database to read data, it works perfect fine.
But when I want to deploy and run the application that read data from a local postgresql database, it just could not find it, and will then use the H2 again.
I have add postgresql dependency in my pom and also configure the properties in the application.properties , it works fine with spring batch in my local Intelij.
So my question is that how could I make my application still read data from the postgresql after it been deployed in the spring-cloud-data-flow-server? Thanks.
Configuration info:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version
<spring.cloud.task.version>2.0.0.RELEASE</spring.cloud.task.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
<version>${spring.cloud.task.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-batch</artifactId>
<version>${spring.cloud.task.version}</version>
</dependency>
You can control what datasource should be configured to SCDF, Tasks, Task-launcher, and even Composed Task Runner. The documentation for these options could be useful.
In your case, though, it sounds like you have 2 different databases: one for SCDF and the other for the Task that SCDF launches, which should be a pretty straightforward setup as long as the datasource properties are configured correctly on both the Boot apps.
It could be that either there's no Postgres driver in the classpath or the datasource properties aren't configured correctly. Review the docs of the connection properties for the supported databases - you could double check for correctness.
I created a spring-boot project to read and write data to Sybase database. The project was working as intended. However, whenever I added activiti dependencies, It says "couldn't deduct database type from database product name 'Adaptive Server Enterprise'". According to my understanding, there are some classes conflicting each other in activiti and spring even though I do not use anything regarding activiti( except the fact that I just opened a folder called processes in the resources directory).
The activiti dependencies I added are:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-jpa</artifactId>
<version>5.21.0</version>
</dependency>
To clarify my point in this, I wanted to use activiti just for workflow purposes and leave the rest of the ETL or database job to spring. If I change database from Sybase to Mysql, the project also works fine even with activiti dependencies. As far as I know activiti has no support for Sybase and apparently, it tries to interfere everything possible and overrides something that was already working at the first place. How can I overcome this problem?
you are trying to use the spring boot starter which automatically tries to configure a database using spring autoconfiguration. Can you clarify with which database do you want to use Activiti? If you want to use Sybase you will need to contribute back to the project with Sybase support. Alternatively, you can not use the starter and depend on the engine directly, this will push you to provide the engine configurations for your spring environment. You can also check the -starter project and adapt as needed.
HTH
I've seen the project via developpez.com
https://www.developpez.com/actu/118014/Cloud-Spanner-Google-lance-pour-le-grand-public-sa-solution-de-bases-de-donnees-globales-offrant-un-bon-compromis-entre-SQL-et-NoSQL/
CockroachDB seems to supports ACID transactions. So my question is:
Is it possible to use it with JPA and JTA?
CockroachDB is compatible with the JDBC API, via the Postgres pgjdbc driver. Since JPA and JTA connect to databases via JDBC, they should be useable against CockroachDB as long as you use the pgjdbc driver.
If you're using Maven, you can add the following declaration to your pom.xml to add a dependency on pgjdbc:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>VERSION</version>
</dependency>
Replace VERSION with a driver version selected from the list in Maven central.