I have a restful api-implementation running in a Tomcat 8 server. I decided to use the embedded Derby version to store data in a database via JDBC (using Eclipse). From my point of view, the official tutorial for the embedded version wasn't very helpfull. I followed the steps here: http://www.nailedtothex.org/roller/kyle/entry/defining-embedded-derby-as-a
My problem is, that the connection to Derby is not found and since I am using the embedded version for Derby, I don't know how to debug the reason for not connecting to Derby.
I copied the derby.jar and derby-shutdown-listener.jar into the lib folder of my Tomcat server. I adapeted the context.xml and the server.xml.
context.xml:
<Context docBase="myapp"
path="/myapp"
reloadable="true">
<ResourceLink name="jdbc/derby"
global="jdbc/derby"
type="javax.sql.DataSource" />
</Context>
I also tried this version of the context.xml:
<Context docBase="myapp"
path="/myapp"
reloadable="true">
<Resource name="jdbc/derby" auth="Container"
driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
username="bot" password="carmeq!"
type="javax.sql.DataSource"
url="jdbc:derby:mydb;create=true"/>
</Context>
server.xml:
<Listener className="org.nailedtothex.derby.DerbyShutdownLifecycleListener" />
And I changed my web.xml:
<resource-ref>
<res-ref-name>jdbc/derby</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
In my Java class concerning the connection to the db, I have the following specification:
String dbURL2 = "jdbc:derby:mydb;create=true";
That is my exception I am receiving when I call my restful function.
javax.servlet.ServletException: java.lang.NullPointerException
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:487)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
When debugging the code, it shows that no suitable driver for the specified url was found.
Moreover, I am using Maven and beside the derby.jar in my Tomcat folder (showing up under Libraries/Apache Tomcat v8.0), I also added the same derby.jar (Version 10.9.1.0) in my pom.xml.
Thanks