To connect to derby database using tomcat as the server initially I added the following to conf/context.xml
of Tomcat :
<Resource name="jdbc/PollDatasource" auth="Container" type="javax.sql.DataSource"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/poll database;create=true"
username="suhail" password="suhail"
maxActive="20" maxIdle="10" maxWait="-1" />
and the Resource-ref
tag in web.xml of the WEB-INF/web.xml
of the project.
<resource-ref>
<description>my connection</description>
<res-ref-name>jdbc/PollDatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
But when I ran a servlet that had to connect to the database,the statement :
connection = dataSource.getConnection();
caused an exception :
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
I haven't understood the reason for this exception yet.
After the exception I removed the Resource
tag from the conf/context.xml
of the Tomcat and placed it in the META-INF/context.xml
of my project.
When I tried the servlet again,it worked without any exception !
What could be the reason I am getting the exception when I place the Resource
tag inside the global context.xml file (i.e inside conf/context.xml) but do not get the exception when I place it inside the context.xml specific to my application ?. (i.e inside META-INF/context.xml)