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

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.

Related

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

multiple hibernate database connections fail

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.

Java API to connect to any kind of database(oracle, mysql, mssql, db2, h2 etc...)

I have a typical requirement from my client. There will be several types of databases that I need to connect to and collect some data from them and invoke a webservice with collected data. He will provide all datasource configurations to connect to respected database. based on datasource I need to figure out which database it is and need to prepare a connection management to connect to respected database.
Before hand, I would like to know, Is there any off the shelf API that could suite my requirement. I googled but no luck and hence landed here to post query. Suggestions are invited.
With Java Database Connectivity (JDBC) you can connect to any of the above databases, and there are open source drivers for those and many more.
Here's an example of using JDBC with MySQL. You use the same method to connect to any datasource with a given JDBC driver.

How to connect to MongoDB on Azure, from Android?

Does anybody have specifics on how to connect an Android application to MongoDB running on Azure roles?
--
Hi, I have MongoDB replica set running on multiple Azure roles in the Cloud Service. I have used the mongo-azure library on GitHub to create the role instances and have them running in Azure.
Most articles online seem to only talk about connecting to Azure-MongoDB locally (via localhost). But, since my application won't be running locally to Azure, I feel that I have to use REST to somehow connect to Azure cloud servers, which may or may not propagate data to the MongoDB replica set.
Does anybody have more specifics on how to connect an Android application to MongoDB running on Azure roles?
(Or, for those that don't have experience with Android/Java: how to connect from non-localhost using non-.NET?)
ps - In other MongoDB questions, people have already answered Android is not natively support by MongoDB, and using non-native methods is fine by me. There are apps out there that already do this, mainly Foursquare. Unfortunately, they use AWS instead of Azure (the requirement for me).
pps - if anybody has any more resources for the linked mongo-library about how it works in more detailed terms, then that would be very helpful too.
UPDATE:
I found the most up-to-date version of mongo-java-driver.jar (currently 2.11.3) and am testing that.
Thanks to another question I've found the particular issue with Android not supported by the java driver, but that issue appears to be resolved.
Possible Solution:
In the Visual Studio project, I created an Input Endpoint for the role. So far that seems to do the trick, using MongoClient mongo = new MongoClient("<my_ip_address>", 27017);
Your 'possible solution' is the right one in my view - you need to open a (load balanced) TCP port in the firewall surrounding your roles and InputEndpoint is the way to do that.
You cannot use an input endpoint if you are doing writes when using a replica set of size > 1 if you are the github solution above. You do not want the Azure load balancer to route a write (insert or update) to a secondary of MongoDB in which case your write will fail.
If you use Azure virtual machines then you can create a port mapping per virtual machine instance and overcome this.

Categories

Resources