No estoy seguro de por qué no soy capaz de conectarme a mi base de datos. Estoy usando JNDI, y maven para ayudar a manejar las dependencias. En mi context.xml en mi carpeta del servidor en eclipse parece:

Could not get JDBC Connection; nested exception is java.sql.SQLException:  
Cannot load JDBC driver class 'org.hsql.jdbcDriver'

context.xml

<Context>

    <!-- Default set of monitored resources. If one of these changes, the -->
    <!-- web application will be 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 this to disable session persistence across Tomcat restarts -->
    <!-- <Manager pathname="" /> -->

    <!-- Uncomment this to enable Comet connection tacking (provides events 
        on session expiration as well as webapp lifecycle) -->
    <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" 
        /> -->
</Context>

esta clase controla el error si es que no se puede conectar:

@ControllerAdvice
public class DatabaseErrorHandler {

    @ExceptionHandler(DataAccessException.class)
    public String handleDatabaseException(DataAccessException ex) {

        System.out.println("Error connecting to 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>

He añadido el hsqldb archivo jar, pero yo realmente no creo que sea necesario que

    <dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>

Desde mi entender solo me falta la de mysql-connector-java dependencia

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>

Mi base de datos el nombre de Spring_Tutorial y estoy usando mySQL Workbench.

Estoy ciegamente falta algo aquí?

InformationsquelleAutor Drew1208 | 2015-05-11

1 Comentario

  1. 2

    Usted está utilizando una base de datos MySQL URL con un HSQL controlador:

    driverClassName="org.hsql.jdbcDriver"
    url="jdbc:mysql://localhost:3306/Spring_Tutorial" />

    Necesita usar un driver de MySQL lugar:

    driverClassName="com.mysql.jdbc.Driver"
    • Yo sabía que estaba ciegamente falta algo. Cortar y pegar de error para el JNDI sitio… Gracias y ejecución de

Dejar respuesta

Please enter your comment!
Please enter your name here