PDA

View Full Version : ClassNotFoundException jdbc driver...


mburbidg
Jun 12th, 2008, 11:45 AM
I'm trying to connect to a MS SQL Server database from one of my bundles. But I cannot seem to set things up correctly so that it finds the driver classes.

I've getting the following exception:


SEVERE: Servlet.service() for servlet rest threw exception
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 16)
at java.net.FactoryURLClassLoader.loadClass(URLClassL oader.java:579)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1138)
at org.apache.commons.dbcp.BasicDataSource.getConnect ion(BasicDataSource.java:882)
at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:79)
at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:577)
at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:641)
at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:670)
at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:678)
at org.springframework.jdbc.core.JdbcTemplate.queryFo rObject(JdbcTemplate.java:721)
at com.adobe.dandelion.jdbc.dao.TenantDao.findByName( TenantDao.java:66)
at com.adobe.dandelion.session.GetSessionCmd.execute( GetSessionCmd.java:69)
at com.adobe.dandelion.session.SessionController.hand le(SessionController.java:68)
at org.springframework.web.servlet.mvc.AbstractComman dController.handleRequestInternal(AbstractCommandC ontroller.java:84)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
at org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :96)
at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:613)
J


The question I have is, given one of these class not found exceptions. How do you tell which bundle is causing the problem?

If I was to look at the stack I would guess that it was the org.apache.commons.dbcp package that was trying to load the class. But that doesn't make sense. It should only be using interfaces defined in javax.sql. The first package that is in one of my bundles, looking up the stack, is com.adobe.dandelion.jdbc.dao. I've added com.microsoft.sqlserver.jdbc to it's import list, but still get the error.

I forgot to mention, I created a bundle from the Microsoft driver jar using bnd. If I look at the manifest bnd created, it correctly exports com.microsoft.sqlserver.jdbc.

I'm using equinox. Is there some place I can put regular libraries that it will load into the jvm and that can be used from any bundle?

Michael-

Any ideas?
Michael-

mburbidg
Jun 12th, 2008, 12:47 PM
The bundle that needed the import dependency was the apache commons dbcp bundle. I added an optional dependency on com.microsoft.sqlserver.jdbc.

I'm still interested in the answer to the question about some place where I can drop a plain jar that would make it available to all the bundles in the platrform.

bjoern.voss
Jun 16th, 2008, 12:41 PM
hmmm .... just a question, but why do all your bundles need to know the driver class?

For instance I have a "datasource" bundle which exposes a plain datasource (pooled by dbcp), so I can use the plain jdbc - API in my bundles ...

or even better the higher abstraction from spring ;)

regards

mburbidg
Jun 18th, 2008, 09:06 PM
As noted by my last post, my bundles don't. It was the apache commons dbcp bundle that needed the import. I had to crack it open and add to it's manifest and then repackage it. I think that it should list as an optional dependency on all the common drivers. I don't know how the Sql Server driver is different. All I know is that I can fix the problem by adding the import dependency.

Costin Leau
Jun 20th, 2008, 08:30 AM
Michael, you are running into a typical class visibility problem - the connection pool doesn't import the driver package as it expects to find it automatically on the classpath.
Have you tried using commons dbcp from BRITS repository? It's already OSGified which means you don't have to add any imports to it - it should just work.