You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Andreas Schneider (JIRA)" <ji...@apache.org> on 2007/05/09 10:43:15 UTC
[jira] Updated: (DERBY-2630) Accessing DB inside jar file fails
when the jar was created by JarOutputStream
[ https://issues.apache.org/jira/browse/DERBY-2630?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Schneider updated DERBY-2630:
-------------------------------------
Component/s: JDBC
> Accessing DB inside jar file fails when the jar was created by JarOutputStream
> ------------------------------------------------------------------------------
>
> Key: DERBY-2630
> URL: https://issues.apache.org/jira/browse/DERBY-2630
> Project: Derby
> Issue Type: Bug
> Components: JDBC
> Affects Versions: 10.2.1.6
> Environment: Windows XP Professional, JDK 1.5
> Reporter: Andreas Schneider
>
> I have tried a pack a db as jar file. When I create it with jar.exe everything is working fine. When i use a JarOutputStream to pack the DB I get the Exception
> java.sql.SQLException: Database 'jar:(D:/p1.jar)p1' not found.
> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
> 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)
> at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
> at org.apache.derby.jdbc.Driver30.getNewEmbedConnection(Unknown Source)
> at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
> at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
> Here the code I use to get the connection.
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
> Properties props = new Properties();
> props.put("user", "JUDOCU");
> props.put("password", "");
> Connection con = DriverManager.getConnection("jdbc:derby:jar:(D:/p1.jar)p1", props);
> con.close();
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Here the code I use to generate the jar file.
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> public class SWUzipUtility {
> /** Trace */
> private static Trace trace = TraceManager.getInstance().getTrace(
> SWUzipUtility.class);
> private ZipOutputStream cpZipOutputStream = null;
> private String[] strSource;
> private String strTarget;
> private long size = 0;
> private int numOfFiles = 0;
> private FileFilter filter;
> public SWUzipUtility(String[] source, String target) {
> this(source, target, null);
> }
> public SWUzipUtility(String[] source, String target, FileFilter filter) {
> super();
> this.strSource = source;
> this.strTarget = target;
> this.filter = filter;
> }
> public void zip() {
> zip(false);
> }
> protected ZipOutputStream createOutputStream(FileOutputStream fos)
> {
> return new ZipOutputStream(fos);
> }
>
> public void zip(boolean append) {
> try {
> for (int i = 0; i < this.strSource.length; i++) {
> File cpFile = new File(this.strSource[i]);
> if (!cpFile.isFile() && !cpFile.isDirectory()) {
> trace.error("Source file/directory Not Found!");
> return;
> }
> }
> FileOutputStream fos = new FileOutputStream(strTarget, append);
> cpZipOutputStream = createOutputStream(fos);
> cpZipOutputStream.setLevel(9);
> for (int i = 0; i < this.strSource.length; i++) {
> File cpFile = new File(this.strSource[i]);
> zipFiles(this.strSource[i], cpFile);
> }
> cpZipOutputStream.finish();
> cpZipOutputStream.close();
> trace.info("Finished creating zip file " + strTarget + " from source "
> + strSource);
> trace.info("Total of " + numOfFiles + " files are Zipped");
> trace.info("Total of " + size + " bytes are Zipped");
> } catch (Exception e) {
> e.printStackTrace();
> trace.error(e.getMessage(), e);
> }
> }
> private void zipFiles(String source, File cpFile) {
> int byteCount;
> final int DATA_BLOCK_SIZE = 2048;
> FileInputStream cpFileInputStream;
> if (cpFile.isDirectory()) {
> if (cpFile.getName().equalsIgnoreCase(".metadata")) { //if directory name is .metadata, skip it.
> return;
> }
> File[] fList = cpFile.listFiles();
> for (int i = 0; i < fList.length; i++) {
> zipFiles(source, fList[i]);
> }
> }
> else {
> try {
> if (cpFile.getAbsolutePath().equalsIgnoreCase(strTarget)) {
> return;
> }
> if (this.filter != null && this.filter.accept(cpFile) == false) {
> trace.info("Cancel file " + cpFile + " because of filter.");
> return;
> }
> trace.info("Zipping " + cpFile);
> size += cpFile.length();
> //String strAbsPath = cpFile.getAbsolutePath();
> setNumOfFiles(numOfFiles + 1);
> String strAbsPath = cpFile.getPath();
> String strZipEntryName = strAbsPath.substring(source
> .lastIndexOf(File.separator) + 1, strAbsPath.length());
> cpFileInputStream = new FileInputStream(cpFile);
> ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
> cpZipOutputStream.putNextEntry(cpZipEntry);
> byte[] b = new byte[DATA_BLOCK_SIZE];
> while ((byteCount = cpFileInputStream.read(b, 0, DATA_BLOCK_SIZE)) != -1) {
> cpZipOutputStream.write(b, 0, byteCount);
> }
> cpZipOutputStream.closeEntry();
> } catch (Exception e) {
> e.printStackTrace();
> trace.error(e.getMessage(), e);
> }
> }
> }
> public void addPropertyChangeListener(PropertyChangeListener listener) {
> propChangeSupport.addPropertyChangeListener(listener);
> }
> public void addPropertyChangeListener(String propertyName,
> PropertyChangeListener listener) {
> propChangeSupport.addPropertyChangeListener(propertyName, listener);
> }
> public void removePropertyChangeListener(PropertyChangeListener listener) {
> propChangeSupport.removePropertyChangeListener(listener);
> }
> public void removePropertyChangeListener(String propertyName,
> PropertyChangeListener listener) {
> propChangeSupport.removePropertyChangeListener(propertyName, listener);
> }
> public int getNumOfFiles() {
> return numOfFiles;
> }
> protected void setNumOfFiles(int numOfFiles) {
> int oldValue = this.numOfFiles;
> this.numOfFiles = numOfFiles;
> this.propChangeSupport.firePropertyChange("numOfFiles", oldValue,
> this.numOfFiles);
> }
> public class SWUjarUtility extends SWUzipUtility {
> public SWUjarUtility(String[] source, String target, FileFilter filter) {
> super(source, target, filter);
> }
> public SWUjarUtility(String[] source, String target) {
> super(source, target);
> }
> @Override
> protected ZipOutputStream createOutputStream(FileOutputStream fos) {
> try {
> return new JarOutputStream(fos);
> } catch (IOException e) {
> }
> return null;
> }
> }
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> When I open the two generated jar files with Winzip they are lokking identical.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.