Search code examples
javaweb-applicationsderby

How to embed Apache derby inside a web application


I just started developing a web-application. I'd like to use Apache derby as a database packaged inside my web-application. Here is the list of jars I am using

derby.jar,
derbyclient.jar,
derbynet.jar,
derbytools.jar

I'm unable to establish connection. Code snippet is here

//start the server
NetworkServerControl networkServerControl= new NetworkServerControl(InetAddress.getByName("localhost"),1527);
networkServerControl.start(null);
//establish connection & create database
connection = DriverManager.getConnection("jdbc:derby://localhost:1527/LoginDB;create=true");

It's throwing this exception

No suitable driver found for jdbc:derby://localhost:1527/LoginDB;create=true

I have placed all the libraries inside the WEB-INF/lib folder of my web application. How to get a connection?

Update:

Adding more detail

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/LoginDB;create=true
Jan 05, 2013 10:41:23 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ReadProperty] in context with path [/Question] threw exception
java.lang.NullPointerException
    at org.humbledevelopers.question.DerbyDemo.main(DerbyDemo.java:96)

code at Line 96: statement=connection.createStatement();


Solution

  • no need to connect to derby using tcp connection if you are trying to run derby as a part of application.

    Get More Details here