multiple hibernate database connections fail - java

I have a java web application that needs to control multiple MySQL databases (same schema) at the same time.
I’m using Tomcat as a web container and hibernate. Connecting up to 3 databases works fine for both reading and writing to the databases.
As soon as I attach the 4th database and write to this database the connection gets lost. I think that this is because of some limitation somewhere but I don’t have the slightest idea what and where.
I would appreciate any help on this.

Related

Connecting to existing in-memory H2 from different application/process

I have a simple Quarkus application that uses an in-memory H2 database. The JDBC connection string has some custom settings: jdbc:h2:mem:quarkus_db;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1;MODE=MariaDB.
I'm trying to connect to the exact same database from a database manager — say DataGrip. After following the documentation, several answers from StackOverflow, and some blog posts, I'm still unable to connect to the same instance and query for any existing data using SQL.
There is something I don't fully understand from the examples. I've seen that initially using a connection like this in the application: jdbc:h2:mem:quarkus_db, and while the same it's up and running, then on the other application/process (DataGrip in my case) using jdbc:h2:tcp://localhost/mem:quarkus_db should work, but I fail to see how the first scheme will create a TCP server.
My goal is to verify some data while the application is running. I understand that when using something like jdbc:h2:mem:*, everything will be lost after the application stops.

Multiple ORACLE DB connections created while running 1 spring boot app

I am trying to understand the correlation between Database connections and spring boot app. My spring boot app is connecting to one schema and I am running 4 such spring boot apps on my system. Each app is connecting to a different schema.
The problem is that these 4 apps are acquiring 50 oracle db connections, but when I close all apps and open DB through oracle sql developer only one connection is acquired.
I don't have enough rep to post this as a comment.
By default Spring Boot uses HikariCP as a connection pooling framework. Some good information can be found at Baeldung, which I recommend using as it covers lots Spring Boot functionality and is almost always up to date.
https://www.baeldung.com/hikaricp
Spring-boot specific information:
https://www.baeldung.com/spring-boot-hikari
While 10 connections are not at all required, you can 'play' around with how much is best (or most optimum) for your app and set it as best fits your design. Usually this will be done by optimizing this as the need arises in your application. 10 is what spring/hikari identifies as a good starting point for most projects.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#data.sql.datasource.connection-pool
Since I had to post this as an answer I'll go a little more in depth in your actual question:
If we think of a connection to a database without a pool we can think of:
The application requests the driver to open a connection to your database
A socket is opened between your application and the database
You are authenticated to the database
Your query runs and the connection is closed
This is fine in a small application without many requests going through, but hopefully you can see the issue here as we scale and get more users. Removing the first 3 steps can make a huge difference.
It should also be noted that while your database holds 3 connections, the connections will be idle and not generating much (if any) load on your database.

Java Derby DB in embedded server mode Change Listener

I'm developing a web application and I am using Derby DB in embedded server mode (embedded and server/client mode). The application is such that when multiple machines connect to it, they share the resources of the database, obviously.. But when one machine queries a statement to the database and changes the record, I need a way to "notify" other machines of the change in the DB so that they can update their UI respectively. I looked for a way to register a Listener to the database, which is going to fire on updates.
I had a look at several questions here, including:
How to implement a db listener in Java
How to make a database listener with java?
But I couldn't find any solution regarding Derby DB. I simply don't know where to start from, here.

Java Embedded Database to Standalone Database

Im workings on java project.its a desktop application (financial application).
I want to when user in offline save all data in embedded database (H2 database) and when user come to online or click on some button save all the new data on Standalone database(My SQL server) server.
Right now i kindda lost with this scenario.
Can some one describe how this should be done or is this possible.
Based on Assumption as your question seem to pointing below requirement,
you have local H2 database
mysql may be on other network.
If you save some data on application then goes to h2 database
one you connected to internet the data should go to mysql database which is on differnet host from h2 local database where application is running.
Solution :
you need to add replication tools which replicate data from one database to another seemlessly.
Refer One of the nice tool : https://www.symmetricds.org/
Let me know if you have any other requirement. Also please provide enough details when raising the questions. Thanks.
Replicating data from H2 DB to Mysql DB using a replicator tool is one way.
Other way to achieve the same is rather than creating a heavy in-memory DB instance on client machine is you can write the same data in file on client machine at some location and write a scheduler program which will check the heart beat of socket and if ping to your server is successful you can read file and upload the data to your actual DB server. Also Writing your own scheduler and data uploader will give you more control.
Other issue with any replicator tool is data type compatibility.
Still if you want to go ahead with any replication tool- you can have a look at Tungsten Replicator - https://docs.continuent.com/tungsten-replicator-4.0/deployment-oracle-fromoracle.html

Android app extern database server

When I want to create an SQLite external database for android application, do I have to have a server with database that is always running?
Yes, since it will be on a server. If the server isn't running, then your application won't be able to get any data from the database.
There's a very important distinction that we're missing here - what it means to have a remote database.
SQLite is a flat-file embedded database engine. You don't have a separate process running SQLite in the background like you would one for MySQL or PostgreSQL or Oracle, nor would you really want to - SQLite as a database is pretty limited in what it can do.
If you say that you're going to have a remote SQLite database, then that implies that you have some server somewhere that writes to and reads from this flat-file database. If you can finagle that somehow, and make it secure, then more power to you - and yes, you could have this accessible remotely for your intents and purposes. Trust me though, you wouldn't want to.
What you're likely looking for is a way to remotely run MySQL or PostgreSQL instead, as these are proper database management systems (DBMS) which will be able to both service remote connections and give you a more expanded set of the SQL language.
Ultimately though, the database server must be running at all times. You wouldn't be able to connect to the database if it's down, and you don't know the lifespan of the app (or when it's going to be accessed, etc).
i got the below information from SQLite home page
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Based on the above statement you don't any server. I hope this information is useful to you.

Categories

Resources