Unable to access a read-only Embedded Derby database from within EAR
javagoodies Sep 29, 2010 10:57 AMI am trying to access a read-only Embedded Derby database. It is available as myDB.jar. This jar has one folder of the Apache Derby database - myDB (log and seg0 folders and service.properties file). This code works fine when I run from a file with a main method. But, when I package it into EAR and deploy it on server it gives error.
This database is packaged with EAR file and deployed on JBoss 5.0.1 server.
The EAR has following contents:
- myWebApp.war
- myEjbs.jar
- myDB.jar
- META-INF/MANIFEST.MF and META-INF/application.xml
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar
myDB.jar is not registered in application.xml
EJB-JAR i.e. myEjbs.jar has the following contents:
- derby.properties
- META-INF/MANIFEST.MF and others such as persistence.xml, etc.
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar
- com.xxx.common.DbUtility.class that has the following code accessing the database:
private static String dbURL = "jdbc:derby:jar:(myDB.jar)";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+ dbName, user, password);
The output of this class is then used by the EJBs in com.xxx.ejbs package.
Following is the error I get:
DEBUG [org.hibernate.engine.StatefulPersistenceContext] (http-127.0.0.1-8080-1) initializing non-lazy collections
INFO [STDOUT] (http-127.0.0.1-8080-1) Connecting to MyDB database ...
INFO [STDOUT] (http-127.0.0.1-8080-1) Loaded database driver: org.apache.derby.jdbc.EmbeddedDriver
INFO [STDOUT] (http-127.0.0.1-8080-1) SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO [STDOUT] (http-127.0.0.1-8080-1) java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
[STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at java.sql.DriverManager.getConnection(DriverManager.java:582)
INFO [STDOUT] (http-127.0.0.1-8080-1) at java.sql.DriverManager.getConnection(DriverManager.java:185)
INFO [STDOUT] (http-127.0.0.1-8080-1) Caused by: java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) Caused by: java.sql.SQLException: Java exception: 'myDB.jar (The system cannot find the file specified): java.io.FileNotFoundException'.
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) Caused by: java.io.FileNotFoundException: myDB.jar (The system cannot find the file specified)
INFO [STDOUT] (http-127.0.0.1-8080-1) at java.util.zip.ZipFile.open(Native Method)
INFO [STDOUT] (http-127.0.0.1-8080-1) at java.util.zip.ZipFile.<init>(ZipFile.java:114)
NFO [STDOUT] (http-127.0.0.1-8080-1) at java.util.zip.ZipFile.<init>(ZipFile.java:131)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.io.JarStorageFactory.doInit(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.io.BaseStorageFactory.init(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.services.monitor.StorageFactoryService.privGetStorageFactoryInstance(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) Unable to connect to database: myDB