0

I'm attempting to connect a Java web application to a ms access database. I get a java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver when running any page of the application that takes data from the database over the GlassFish server.

Within the same application I have a 'test app' that successfully takes all data from the database and prints to the console. I'm trying to run the same method from the underlying database class to retrieve the data from a .jsp.

I've checked that the JDK has the necessary class.

I'm using

Netbeans 8.0.2 (64 bit)

JDK 7.0.0_67 (64 bit)

MS Access 2010 (64 bit)

GlassFish server 4.1

Upgrading to JDK 8 is not an option, this app is for a University project that has to run on the Unis computers which use JDK 7.

Exception

Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:259)
    at plymoutheventsaccess.DatabaseConnector.createConnection(DatabaseConnector.java:42)
    at org.apache.jsp.eventList_jsp._jspService(eventList_jsp.java:62)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Any help much appreciated.

Tony

tonyedwardspz
  • 1,707
  • 2
  • 22
  • 45
  • Is the JDBC driver in the `war` file? – meskobalazs Feb 17 '15 at 13:49
  • @meskobalazs Where can I find the war file? – tonyedwardspz Feb 17 '15 at 13:59
  • I am not familiar with Netbeans, but it should be in the `dist` folder. The `war` file is the *web application archive* which is deployed on Glassfish. The JDBC driver `jar` should be in `WEB-INF\lib` inside the archive. If it's not there, then that is your problem. – meskobalazs Feb 17 '15 at 14:01
  • I seems like that is the problem. Is it the rt.jar file that I need to include? – tonyedwardspz Feb 17 '15 at 14:10
  • No, that is the Java runtime, you should not bundle that. Are you sure that glassfish is configured to use JDK7? – meskobalazs Feb 17 '15 at 14:20
  • 1
    Are you sure that your Glassfish server runs with Java 7? The JDBC-ODBC-Bridge-Driver is not included in Java 8 anymore. Until Java 7 this driver is included in the JRE. – vanje Feb 17 '15 at 14:21
  • The JDBC-ODBC-Bridge was never meant to be used in production code. Especially not with an Access database in a web application. Access is a pure desktop database and is the worst choice to use with a Java web application. You should really consider to use a real server side database. Even an in-process Derby database is better than MS Access. – vanje Feb 17 '15 at 14:25
  • @vanje I completely agree about not using access, however I have to as its a requirement within the assignment brief. How do I check and change the JDK glass fish is using. I can't seem to find a way of doing it? – tonyedwardspz Feb 17 '15 at 14:29
  • Hm, I'm not a Glassfish expert. Maybe you find this usefull: http://stackoverflow.com/questions/10444959/how-do-i-specify-the-jdk-for-a-glassfish-domain – vanje Feb 17 '15 at 14:35
  • Most likely it uses the default, so check your `JAVA_HOME` – meskobalazs Feb 17 '15 at 14:39
  • After changing bat files, syslinks and paths, I uninstalled JDK 8 from my system. It now works. Thanks for the help. – tonyedwardspz Feb 17 '15 at 16:08
  • You should post your solution as an answer to the question to mark it as solved. – unwichtich Feb 17 '15 at 20:50

1 Answers1

0

I followed the suggested made by commenters on the question but none worked. In summary I tried:

  • Setting JAVA_HOME
  • Editing Glassfish BAT files
  • Changing where the Java syslink pointed
  • Including JDBC within the deployment package

To solve my issue I removed JDK 8 from my system completely. After this there was no further configuration needed, worked straight away.

tonyedwardspz
  • 1,707
  • 2
  • 22
  • 45