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

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks