Can I connect the jdbc connected static Derby data file in remote repository? - derby

I have to load two Derby instances that reference same data Derby file in a remote repository.
Is it possible? How can I achieve this? Would you give detailed information?

Two different connections in the same Derby app is ok because Derby uses Java synchronization features to coordinate their access to the db.
Two different apps cannot use Java synchronization because that only works inside a single Jvm class loader so instead Derby locks the db and only allows one app at a time to access the db.
That is the benefit of the Derby network server because many apps can access the db simultaneously via the network server.
There is a hybrid mode by which one embedded app can also serve as the network server for other apps but it is complex and usually not the best choice.
Update: You can find more information about embedded servers in these docs: http://db.apache.org/derby/docs/10.11/adminguide/cadminov825149.html and http://db.apache.org/derby/docs/10.11/adminguide/radminembeddedserverex.html
or by searching the Internet for "Derby embedded server".

Related

Elixir/Phoenix - Connect to external database

I connected the main database in the dev.exs and it works fine. But in my project I plan to use several databases. I know that in the file dev.exs can connect multiple databases but this option doesn’t suit me. Databases connections will be stored in the main project database. I want to know: how can I connect to different databases using the elixir code without using a file dev.exs?
You can start multiple instances of your Repo with different connection options.
Then, use the Repo.put_dynamic_repo/1 function to tell the Repo which of the databases should be used for queries in the current process. (The documentation for this function also tells you how to start more of the same repo).
There's also a discussion document that goes more in-depth about this topic: https://hexdocs.pm/ecto/replicas-and-dynamic-repositories.html

Multiple connections for Embedded Databases

I'm working with an H2 database in embedded mode and I came up with this quote in H2 documentation (here).
In embedded mode, an application opens a database from within the same
JVM using JDBC.
In Derby documentation (here), I came up with this.
If you use the embedded driver, two separate instances of Derby cannot
access the same database. If a Derby instance attempts to access a
running database, an error message appears, and a stack trace appears
in the derby.log file. If you want more than one Derby instance to be
able to access the same database, you can use the Network Server.
I would really appreciate if someone can elaborate on why is that only the same JVM can access the database in embedded mode.
Thank you.

DB High availability through jdbc connection proxy?

I need to have a high availability database system but I can't do it through database cluster or master/slave. I need a jdbc proxy that knows to update multiple data source for a single update statement. I found HA-JDBC project http://ha-jdbc.github.com/ that does that but I was wondering if there are similar or better library than HA-JDBC.
You can see other project around HA features: Sequoia/C-JDBC (http://c-jdbc.ow2.org).
But some links on page are broken ;(

Using JDBC on Google App Engine (GAE)

GAE doesn't support JDBC but is there a way to use it anyway? Is there a way to connect to an external Oracle db to store structured information using the RDBMS pattern? Is the a wrapper or a runtime lib that makes it possible to connect to an external RDBMS using JDBC?
I don't want to use GAE's in-house MySQL cloud hack.
You cannot open sockets on GAE, that's why you cannot open a JDBC connection for any outside RDBMS.
BTW, today they launched a trusted tester program for sockets on GAE:
http://googleappengine.blogspot.com.br/2012/09/app-engine-172-released.html
But I believe this is not the case they are trying to address

H2 Database multiple connections

I have the following issue:
Two instances of an application on two different systems should share a small database.
The main problem is that both systems can only exchange data through a network-folder.
I don't have the possibilty to setup a database-server somewhere.
Is it possible to place a H2 database on the network-folder and let both instances connect to the database (also concurrently)?
I could connect with both instances to the db using the embedded mode if I disable the file-locking, right?
The instances can perfom either READ or INSERT operations on the db. Do I risk data corruptions using multiple concurrent embedded connections?
As the documentation says; ( http://h2database.com/html/features.html#auto_mixed_mode
)
Multiple processes can access the same database without having to start the server manually. To do that, append ;AUTO_SERVER=TRUE to the database URL. You can use the same database URL independent of whether the database is already open or not. This feature doesn't work with in-memory databases.
// Application 1:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
// Application 2:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
From H2 documentation:
It is also possible to open the database without file locking; in this
case it is up to the application to protect the database files.
Failing to do so will result in a corrupted database.
I think that if your application use always the same configuration (shared file database on network folder), you need to create an application layer that manages concurrency

Resources