Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC Connection URL For Embedded Derby in a Webapp

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.

like image 982
dev Avatar asked Oct 14 '22 18:10

dev


1 Answers

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());
like image 142
dev Avatar answered Nov 02 '22 08:11

dev