Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Open resource database using currentContext

Anonymous
2010-01-07
2014-01-19

  • Anonymous
    2010-01-07

    Hi,

    Using a resource connection (jdbc:hsqldb:res: ) you can easily distibute your database as a single zip-file but because the file must be added to the classpath it is limited. Since you can't change the system class loader (without hack, http://forums.sun.com/thread.jspa?threadID=300557) you can't add or change the file att runtime. But you can change the thread context class loader.

    So I suggest that you first try to load the resource using

    getClass().getResource(...)
    

    . If that fails, try to load the resource from the context classloader,

    Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
    

    .

    The optimal solution would be to create a new type of connection (jdbc:hsqldb:zip: ) but that is a bigger task to do.

    /Johan

     
  • Fred Toussi
    Fred Toussi
    2010-01-12

    Thanks,
    I have changed the code as suggested. Please check with the code in svn /base/trunk