When the database in the zip file is fairly large you cannot query from the 
zipped database directly.
Weird thing is it works fine in the H2 Console that you can install 
directly. Just not in the java example.
Taking the example 
from 
https://github.com/h2database/h2database/blob/master/h2/src/test/org/h2/samples/ReadOnlyDatabaseInZip.java
 
and increasing the number of rows and size of each row (modified code below)

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.h2.store.fs.FileUtils;
import org.h2.tools.Backup;
import org.h2.tools.DeleteDbFiles;

public class MainApp {
 public static void main(String... args) throws Exception {

 // delete all files in this directory
 FileUtils.deleteRecursive("~/temp", false);

 Connection conn;
 Class.forName("org.h2.Driver");

 // create a database where the database file is split into
 // multiple small files, 4 MB each (2^22). The larger the
 // parts, the faster opening the database, but also the
 // more files. 4 MB seems to be a good compromise, so
 // the prefix split:22: is used, which means each part is
 // 2^22 bytes long
 conn = DriverManager.getConnection(
 "jdbc:h2:split:22:~/temp/test");

 System.out.println("adding test data...");
 Statement stat = conn.createStatement();
 stat.execute(
 "create table test(id int primary key, name varchar, name2 varchar) " +
 "as select x, space(2000), space(2000) from system_range(1, 200000)");

 System.out.println("defrag to reduce random access...");
 stat.execute("shutdown defrag");
 conn.close();

 System.out.println("create the zip file...");
 Backup.execute("~/temp/test.zip", "~/temp", "", true);

 // delete the old database files
 DeleteDbFiles.execute("split:~/temp", "test", true);

 System.out.println("open the database from the zip file...");
 conn = DriverManager.getConnection(
 "jdbc:h2:split:zip:~/temp/test.zip!/test");
 stat = conn.createStatement();

 ResultSet res = stat.executeQuery("select id from test");
 // the above never completes

 conn.close();
 }
}

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to