It is necessary to restore the h2 database. I have a file to recover, but its extension is .db, not .zip. I run h2 through the java -jar ./h2-1.4.190.jar -browser command. In the JDBC URL I indicate: jdbc:h2:file:/opt/backup/my.h2.db . I specify the password and login. The connection is made, I get to the database, but I don’t see my scheme. What should I do?
You shouldn't include a file name extension into JDBC URL. The valid URL for such file is jdbc:h2:/opt/backup/my;MV_STORE=FALSE;MVCC=FALSE.
Please note that 1.4.190 is a very old version, use it only if the database was really created with that version. (For the latest version of H2 exclude MVCC setting from the URL, it was removed from H2.)
Use a copy of your file. If it can't be opened normally, use a Recover Tool.
https://h2database.com/html/advanced.html#using_recover_tool
Related
I am trying to run select query in jmeter. I am getting this response in listners "Cannot create PoolableConnectionFactory" I have attached my myphpadmin page which I use to create db. Thanks in advance.
.png
JDBC jar should be in lib folder:
Fully qualified name of driver class. (Must be in JMeter's classpath - easiest to copy .jar file into JMeter's /lib directory).
I assume you use your jar for MySQL DB:
The list of the validation queries can be configured with jdbc.config.jdbc.driver.class property and are by default:
MySQL
com.mysql.jdbc.Driver
You need to put the .jar into the "lib" folder of your JMeter installation (or other folder which is in JMeter Classpath
You need to restart JMeter to pick the .jar
Check out MySQL Database and JMeter - How to Test Your Connection for more information
On JMeter side check:
driver of MySQL (correct version) is in lib folder. The Jar not a zip.
The URL format is correct based on this document, there seems to be a space before database name in your URL
Login / password are also correct, check for strange characters or bad copy/paste
If all those are ok, then you're most probably facing same issues as the ones described here:
https://stackoverflow.com/a/2985169/460802
I'm trying to setup ObjectDB. I am able to create a database and view it with the explorer, using the embedded-server mode to be able to keep the explorer open while running my program. This all works fine, when my database is in the $objectdb/db/ directory.
However, I'd like to be able to do this when my database is in another directory (thus not in $objectdb/db/). When I'm not using the explorer, the database looks fine. I can also open the explorer to view the database. But... I can not keep the connection to my database open in the explorer while running my program (and thus making changes to the database).
What I have tried/have been thinking about:
The database and the explorer have to use the same .conf file. I think the explorer uses the conf file in the $objectdb home directory, but I can't figure out how to configure my database in the other directory to listen to that conf file, too. How can I create a project (or database) specific conf file for a database that's not in the $objectdb home directory?
In general it feels strange to me that there would be one conf file for all your ObjectDB databases.
I copied both the explorer.exe and objectdb.conf to the directory my database is in, hoping this would work. However, nothing happens when I try to run the exe file. I think this is because the exe (and the explorer.jar, tried that one, too) rely on objectdb.jar, but I couldn't find that anywhere. I found objectdb-2.7.1_01.jar and copied that into the directory the database and explorer were in, but that didn't help.
As for an MWE, I followed this tutorial, using IntelliJ.
Try the following:
Open the database in embedded mode with a path that specifies a free port for the embedded server, e.g. "$objectdb/db/my.odb;port=9999"
Access this database in client mode using "objectdb://localhost:9999", or in the Explorer, select File -> Open C/S Connection, specify 9999 as the port and keep the database path empty or /
objectdb.jar is available when you download ObjectDB as a zip file (in which you also find the Explorer), you can also rename the file from Maven, which contains a version number to objectdb.jar.
I have to write JUNIT for repository class using HSQL DB.
I am not supposed to use any SQL command to load the data into HSQL DB.
Instead I need to use one external jar called abc.jar which will load all the schema and data from production database into HSQL.
abc.jar was working fine as standalone i.e. exporting schema and table from real database into HSQL .
In the current package I added abc.jar as dependent. When I call a method in abc.jar to export the data in #before of repository jUnit I'm getting HSQL connection exception.
Is it a possible approach?
It is a possible approach.
The connection URL in both the standalone setup and the test setup must be an absolute URL. And the export of data must occur in the same JVM process. If you are using a file: database, the path to database files must be absolute. If you are using a mem: database, the paths are absolute, provided they are used in the same JVM process.
I created a software using NetBeans and SQLite database. When I clean and build, the executable jar file and database work fine. It can read and write data from the database.
Then I created .exe file using "install creator" and after installing the software, the same dist folder is created in Program files on my Windows PC. When I run the executable jar file from that dist folder, it can only read the database, but can't write. I get this message
java.sql.SQLException:attempt to write a readonly database
Can anyone please help me solve this problem? Thanks in advance.
check this
The problem, as it turns out, is that the PDO SQLite driver requires that if you are going to do a write operation (INSERT,UPDATE,DELETE,DROP, etc), then the folder the database resides in must have write permissions, as well as the actual database file.
I found this information in a comment at the very bottom of the PDO SQLite driver manual page.
You should write the user specific data to the Application Data folder of current user.
You can get the ROAMING directory from
String path = System.getenv("APPDATA");
Or if you want to make it platform independent you can use getProperty which will give you users home directory and then you can write to specific directory:
String path = System.getProperty("user.home");
You can form the sqlite on path like
String sqliteUrl = "jdbc:sqlite:"+path+"sample.db";
Use this code line:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\databasefile.db"
I can say this is the proper way of creating DB in application folder on to the drive like C:\ without permission
Use this code line:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Yourfile.db"
I can say this is the proper way of crating DB without permission on to the drive like C:\
I'm using H2 embedded database for my application. I would like to contain everything the application needs in it's own Jar, including it's database if possible. My app does not need to create temp files or anything, so basically the user just runs the Jar.
Is it possible to embed a database inside a Jar, and be able to INSERT new records as well as just SELECT out?
EDIT: Just to clarify, I'm not looking to embed the H2 driver jar inside my distributable jar, I'm looking to embed the h2 database file (someDatabase.h2.db file) inside a Jar and still be able to write/read from that database.
If you wish to embed the myDatabase.h2.db file inside the .jar, you can do so, but you'll have read-only access to the database. As .jar files are read-only, you can't modify them and therefore can't execute INSERT, DELETE or any DDL command.
That being said, below is an explanation on how to embed it read-only.
According to H2's documentation:
The JDBC URL "jdbc:h2:~/myDatabase" tells the H2 Engine to look for a database file named myDatabase.h2.db in the home directory of the current user.
The JDBC URL "jdbc:h2:file:/myDatabase" tells the H2 Engine to look for a database file named myDatabase.h2.db in the current directory (where the java program was executed).
If you embed the h2.db file inside a .jar, it is not accessible in a plain way. It is only accessible as a file inside a zip file.
In order to make H2 uset it, you have to use a zip as URL:
jdbc:h2:zip:~/data.zip!/test
See more in "Read Only Databases in Zip or Jar File".
When you embed the file as a resource in the jar, you may get it's relative url. Using...
MyClass.class.getClassLoader().getResource("myDatabase.h2.db")
...you'll get something like:
jar:file:/C:/folder1/folder2/myJar.jar!/myDatabase.h2.db
You can then manipulate it as a String and pass as JDBC URL connection to H2.