5

I have a derby database that is deployed along with my webapp to WEB-INF/classes/myDb

What should my jdbc.connection url be to connect so that I can write to the database?

I am trying

jdbc:derby:myDb;

and it can not find the database. I need to be able to modify the database. If i put classpath:myDb, it finds it, but it is unfortunately read only per the derby docs.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
dev
  • 2,949
  • 5
  • 37
  • 48

1 Answers1

4

i solved it by setting my jdbc connection url at runtime and using:

        StringBuilder derbyUrl = new StringBuilder("jdbc:derby:");
        derbyUrl.append(servletContext.getRealPath("/"));
        derbyUrl.append("/WEB-INF/classes/myDb;");
        dataSource.setUrl(derbyUrl.toString());
dev
  • 2,949
  • 5
  • 37
  • 48
  • +1: I've had to do very similar things myself (my solution was a custom Spring factory class did the rewrite, but that's conceptually almost identical) and I've yet to see any substantially-better ideas. Mind you, you might also make the argument that in a production deployment, the webapp files shouldn't be writable at all, so requiring an external database connection instead… – Donal Fellows Jan 01 '11 at 15:08