Is it possible to connect to an embedded Neo4j database the same way you would do with an H2 in-memory database to mock an Oracle database?
I've tried to do this:
final BoltConnector boltConnector = new BoltConnector("bolt");
graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(DB_PATH)
.setConfig(boltConnector.type, BOLT.name())
.setConfig(boltConnector.enabled, TRUE)
.setConfig(boltConnector.listen_address, listenAddress("127.0.0.1", 7688))
.setConfig(boltConnector.encryption_level, DISABLED.name())
.setConfig(GraphDatabaseSettings.auth_enabled, FALSE)
.newGraphDatabase();
And then make a request using the JDBC Bolt driver with the following spring.datasource configuration:
spring:
profiles: test
datasource:
driver-class-name: org.neo4j.jdbc.bolt.BoltDriver
url: jdbc:neo4j:bolt://127.0.0.1:7688/?nossl
But I always get the following error:
Unable to connect to 127.0.0.1:7688, ensure the database is running and that there is a working network connection to it.
Of course the embedded database works when I use the graphDb instance and execute requests against it. But I want my application to connect to the embedded database as it does when connecting to a remote Neo4j database.
This is for testing purpose.
I finally RTFM...
I had the following dependency in my pom.xml:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.4.0</version>
</dependency>
Then I found this: https://neo4j.com/docs/java-reference/current/tutorials-java-embedded/#tutorials-java-embedded-bolt
The documentation is a bit outdated because it uses deprecated configuration. But they explain this:
The Neo4j Browser and the official Neo4j Drivers use the Bolt database
protocol to communicate with Neo4j. By default, Neo4j Embedded does
not expose a Bolt connector, but you can enable one. Doing so allows
you to connect the services Neo4j Browser to your embedded instance.
And they make clear the correct dependency to use is:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-bolt</artifactId>
<version>3.4.0</version>
</dependency>
Related
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)
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 .
My spring boot application cannot read from an Oracle DB instance.
If I configure the application to automatically create the schema and populate the DB via a data.sql file, then it works perfectly, like so:
spring:
datasource:
initialization-mode: always
...
jpa:
hibernate:
ddl-auto: create
But then if I then change the configuration to:
spring:
datasource:
initialization-mode: never
...
jpa:
hibernate:
ddl-auto: validate
and then restart the spring boot application, it can no longer read from the DB, even though all the tables and data that it created before the restart is still there in the DB.
Has anyone experienced this issue before? Or would you know where I could even start to try debugging it?
This is the Oracle version:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
This is the driver I'm using:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
And the version of JPA:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
and it's spring boot version 2.3.3
UPDATE:
The appears to happen after I write to the DB via Spring Boot, i.e. insert a new record, and then restart the application.
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
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.