How to find out H2 DB is running in memory - h2

I know it's very basic question. But i have learned that H2 DB can run in-memory and like normal DB(e.g mysql). How can i find out that my H2 is running in-memory?
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.`**

According to my researches, i found that we have to change connection url to use in memory DB.
To use h2 on in-memory:
<property name="hibernate.connection.url"
value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" />
To use h2 on HDD:
<property name="hibernate.connection.url"
value="jdbc:h2:~/test;DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE"/>
Explanations of Connection URLS:
According to:h2database.com
DB_CLOSE_DELAY=-1
By default, closing the last connection to a database closes the database. For an in-memory database, this means the content is lost. To keep the database open, add ;DB_CLOSE_DELAY=-1 to the database URL. To keep the content of an in-memory database as long as the virtual machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1.
AUTO_SERVER=TRUE
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. Example database URL:

Related

how to change database connection without restarting server when using AbstractRoutingDataSource

I am using AbstractRoutingDataSource to store data sources which are stored in database during spring boot application startup.
System can switch to correct database during program running.
When end users manual change database connection information from UI (like change password every 6 months), then sysem need to reload data sources information.
According to testing, even sytem reset target data sources, the old jdbc connection is used.

find who is connecting to database using db link

currently, we are using oracle 8i and we are working to decommisson it.
I need to find out which all other databases are connecting to our database using db link.
Please note, I am not looking for the connection from our database to others database. I already got that information using all_Db_links.
If you audit connections to the database or look at the listener log, that will tell you the machines that are connecting to the database and the application that is connecting (that information is coming from the client so it could be spoofed but I'm assuming no one is actively trying to hide information from you). That should allow you to determine which connections are coming via database links. That may not tell you which database on the particular server is connecting if there are multiple databases on the same server using the same Oracle Home. But it should narrow it down to a relatively small number of databases that you can manually check.

Can't find tables and data of my H2 database

A webapp is using following configuration to store some data in DB:
spring.datasource.continueOnError=true
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:mydb
I was trying to reach this DB using H2 Console, but something is wrong. There are no tables even though I know they were created. I can also access any made up JDBC:URL like jdbc:h2:mem:fakeXYZ just as well with same result. What is goning on here? How can I see this DB tables and data?
Your JDBC URL specifies a named in-memory database which by default only will be available for connections from within the same virtual machine.
You can either change the URL to use a file-based database, or you will have to start a TCP server to allow for connections from other processes.

glassfish JDBC Connection Pooling and oracle global temporary table same sessionId

Before I start with my question, I would like to clarify that I am java/j2ee developer and have limited understanding of things on oracle side.
I am using glassfish server with JDBC connection Pooling and in back side, oracle database.
Also i am using global temporary table of oracle to execute some work flow.
i am storing session specific data in global temp table.
Now my issue is most of the time i am getting the same sessionId for each connection.
Does that means i can't use glboal temporary table with glassfish JDBC connection Pooling.
Another interesting thing is if i removed connection pooling then i am getting different sessionID for each connection.
Please provide your suggestions.
When using Connection Pooling it's always best to not leave states in the database session when the connection is released into the pool. That's because there is no guarantee that you'll get back the same connection the next time you need one. A global temp table (GTT) is an example of such a state and belongs to one Database session, or to one JDBC connection (there is a 1-1 mapping between DB session and JDBC connection). It won't be visible if you use another JDBC connection.
So if your business logic requires that you use a GTT then you should not release the connection back to the pool until you're dong using this GTT. Note that this goes against the best practices which recommend to release the connection back to the pool as soon as possible. As an alternative you may use a normal table and commit your temporary results into it so that they can be accessed through any other connection.

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