db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Vinca <micha...@vinca.org>
Subject Can you use createFrom to create a database from a backup database stored in a JAR file?
Date Wed, 21 Sep 2005 17:55:17 GMT
Hello,
	I wasn't sure if this was going to work or not. There was nothing in  
the documentation to suggest it would, I was just hopeful. I tried  
searching the archives for "createFrom" but only got one hit, so I hope  
this is not a repeat question.
	I am attempting to create a writable database from a read only  
database in a JAR file. The idea is to have a clickable JAR file that  
can determine if an external database exists, and if not, creates it  
from an original (not blank) database stored within the JAR file. A  
code snippet follows:

         // Connect to the database
         try
         {
             Class.forName( "org.apache.derby.jdbc.EmbeddedDriver"  
).newInstance(); //Start up derby
         }
         catch( Exception e )
         {
             e.printStackTrace();
             throw new RuntimeException( e );
         }
         String databaseUri =  
PreferenceController.Instance().getPreferenceDirectory().getAbsolutePath 
() +
                 java.io.File.separatorChar + "vEat";
         try
         {
             // Check to see if the database exists
             java.io.File database = new java.io.File( databaseUri );
             if( !database.exists() )
             {
                 databaseUri = "jdbc:derby:" + databaseUri;
                 System.out.println( "Attempting to create database: " +  
databaseUri );
                 // Database does not exist. Copy the default to the  
preference directory
                 Connection conn = DriverManager.getConnection(  
databaseUri +
                         ";createFrom=/org/vinca/vEat/database/vEat" );
                 conn.close();
             }
         }
         catch( SQLException e )
         {
             // Couldn't access the database.

(Please excuse my poorly named databaseUri variable...)
The JAR file does include the database, I checked.

I get the following output (some stack removed):

Attempting to create database:  
jdbc:derby:/Users/michaelj/Library/Preferences/vEat/vEat
SQL Exception: Failed to start database  
'/Users/michaelj/Library/Preferences/vEat/vEat', see the next exception  
for details.
         at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  
Source)
         at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  
Source)
         at  
org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
…
ERROR XBM0Y: Backup database directory /org/vinca/vEat/database/vEat  
not found. Please make sure that the specified backup path is right.
         at  
org.apache.derby.iapi.error.StandardException.newException(Unknown  
Source)
         at  
org.apache.derby.impl.services.monitor.PersistentServiceImpl.recreateSer 
viceRoot(Unknown Source)
…
Exception in thread "main" java.lang.RuntimeException: SQL Exception:  
Backup database directory /org/vinca/vEat/database/vEat not found.  
Please make sure that the specified backup path is right.
         at org.vinca.vEat.controller.IdMapper.<init>(IdMapper.java:62)
…
Caused by: SQL Exception: Backup database directory  
/org/vinca/vEat/database/vEat not found. Please make sure that the  
specified backup path is right.
  …

So I assume that my attempt is not supported by Derby. Can anyone  
confirm? Also, anyone have any alternate suggestions on how to  
accomplish creating a single JAR that can use a pre-made, but writable,  
database?

Thank you,

Mike Vinca
Mime
View raw message