mysql - Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot load JDBC driver class 'org.hsql.jdbcDriver' -
i not sure why unable connect database. using jndi, , maven handle dependencies. in context.xml in server folder in eclipse looks like:
could not jdbc connection; nested exception java.sql.sqlexception: cannot load jdbc driver class 'org.hsql.jdbcdriver'
context.xml
<context> <!-- default set of monitored resources. if 1 of these changes, --> <!-- web application reloaded. --> <watchedresource>web-inf/web.xml</watchedresource> <watchedresource>${catalina.base}/conf/web.xml</watchedresource> <resource name="jdbc/spring_tutorial" auth="container" type="javax.sql.datasource" maxactive="100" maxidle="30" maxwait="10000" username="root" driverclassname="org.hsql.jdbcdriver" url="jdbc:mysql://localhost:3306/spring_tutorial" /> <!-- uncomment disable session persistence across tomcat restarts --> <!-- <manager pathname="" /> --> <!-- uncomment enable comet connection tacking (provides events on session expiration webapp lifecycle) --> <!-- <valve classname="org.apache.catalina.valves.cometconnectionmanagervalve" /> --> </context>
this class handles error if unable connect:
@controlleradvice public class databaseerrorhandler { @exceptionhandler(dataaccessexception.class) public string handledatabaseexception(dataaccessexception ex) { system.out.println("error connecting database: "+ex); return "error"; } }
pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.spring.practice</groupid> <artifactid>offers</artifactid> <version>0.0.1-snapshot</version> <packaging>war</packaging> <build> <sourcedirectory>src</sourcedirectory> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.4</version> <configuration> <warsourcedirectory>webcontent</warsourcedirectory> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>4.1.6.release</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.35</version> </dependency> <dependency> <groupid>javax.validation</groupid> <artifactid>validation-api</artifactid> <version>1.1.0.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate</artifactid> <version>3.5.4-final</version> <type>pom</type> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>5.1.3.final</version> </dependency> <dependency> <groupid>commons-dbcp</groupid> <artifactid>commons-dbcp</artifactid> <version>1.4</version> </dependency> <dependency> <groupid>hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>1.8.0.10</version> </dependency> </dependencies> </project>
web.xml
<description>database</description> <resource-ref> <description>db connection</description> <res-ref-name>jdbc/spring_tutorial</res-ref-name> <res-type>javax.sql.datasource</res-type> <res-auth>container</res-auth> </resource-ref>
i added hsqldb jar file did not think needed it
<dependency> <groupid>hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>1.8.0.10</version> </dependency>
from understand need mysql-connector-java dependency
<dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.35</version> </dependency>
my database's name spring_tutorial , using mysql workbench.
am blindly missing here?
you're using mysql url hsql driver:
driverclassname="org.hsql.jdbcdriver" url="jdbc:mysql://localhost:3306/spring_tutorial" />
you need use mysql driver instead:
driverclassname="com.mysql.jdbc.driver"
Comments
Post a Comment