Hibernate with JNDI: Cannot create JDBC driver of class '' for connect URL 'null'
I tried to use Hibernate for working with MySQL through JNDI but can't (from catalina.out):
INFO: Deploying web application archive mystamps.war
Cannot create JDBC driver of class '' for connect URL 'null'
java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
(I reduce full stack trace because it's useless: no cause or any other exceptions.)
spring-servlet.xml:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdb开发者_C百科c/mystamps" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="ru.mystamps.web.dao" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
</props>
</property>
</bean>
/etc/tomcat6/server.xml:
<Host name="my-stamps" appBase="webapps"
unpackWARs="false" xmlValidation="false"
xmlNamespaceAware="false">
</Host>
/etc/tomcat6/Catalina/my-stamps/mystamps.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context path="" docBase="mystamps" allowLinking="true" reloadable="true">
<Resource name="jdbc/mystamps" auth="Containter"
type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="password" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mystamps" />
</Context>
I use following versions: Spring MVC 3.0.5, Hibernate 3.6.2.Final, MySQL 5.1.52 , mysql-connector-java 5.1.15 (located at /usr/share/tomcat6/lib) and Tomcat 6.0.30
I use google and try to fix it by myself, but without luck :(
Can you help me -- what's I doing wrong?
TIA
Have you tried putting the mysql-connector jar file in the WEB-INF/lib folder of your packaged war file?
Or maybe the following link can be helpful: http://ubuntuforums.org/showthread.php?t=430133
Had this same error, when I moved the location that the JNDI is declared to context.xml and my error went away. This error means that spring cannot find the JNDI infformation. There was no need for a link in the server.xml
/etc/tomcat6/context.xml
<?xml version='1.0' encoding='utf-8'?>
<Context path="" docBase="mystamps" allowLinking="true" reloadable="true">
<Resource name="jdbc/mystamps" auth="Containter"
type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="password" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mystamps" />
</Context>
Ref: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
Hope this helps!
精彩评论