Can't find tables and data of my H2 database - h2

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.

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.

Hive JDBC fails to connect configured schema

I am able to connect to Hive using hive-jdbc client and also using the beeline.Typical url is,
jdbc:hive2://hive_thrift_ip:10000/custom_schema;principal=hive/hive_thrift_ip#COMPANY.COM
Unfortunately the connection is always established to the 'default' schema of Hive , and it is not considering the configured schema name in the url. I use the org.apache.hive.jdbc.HiveDriver class
It always takes me to the tables of the default schema. Still I am able to access the tables from other schema using the schema name prefix to the tables, like custom_schema.test_table
Kindly let me know if I missed any property or configuration in the connection creation part which will help me in getting the session exclusively for the schema that configure in the url.
Many thanks.

How to find out H2 DB is running in memory

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:

Database url in jmeter?

I have a database stored at a server. I want to load test the server using jmeter.It requires a field called database url? Now what i am supposed to fill in that?
Also it is asking for jdbc driver class? What will be the values of these two?
JMeter uses JDBC.
What is your db ? Oracle, mysql ...
Each Db provides drivers you need to put in jmeter/lib folder.
For url each driver has a syntax, examples:
http://www.petefreitag.com/articles/jdbc_urls/
Then you need to add login/password
your database url should be -jdbc:mysql://localhost:3306/
database url is the host address of the database u can see that when you connect mysql from gui using SQl yog
is the database name that you have created in mysql
Your driver class should be -com.mysql.jdbc.driver
user name and password of the database

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