Hola:
Estoy haciendo un aplicacion web la que utilizo un DataSoure. El codigo del context.xml es el siguiente:
 
<Context antiJARLocking="true" crossContext="false" debug="0" docBase="Ejercicio5" path="/Ejercicio5" reloadable="true">
 <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/>
  <Resource auth="SERVLET" name="jdbc/quoting" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/quoting">
        <parameters>
            <name>driverClassName</name>
            <value>com.mysql.jdbc.Driver</value>
        </parameters>
        <parameters>
            <name>driverName</name>
            <value>jdbc:mysql://localhost:3306/quoting</value>
        </parameters>        
    </ResourceParams>
</Context>
 
El archivo web.xml:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Main</servlet-name>
        <servlet-class>Servlets.Main</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Main</servlet-name>
        <url-pattern>/Servlets/Main</url-pattern>
    </servlet-mapping>
    ...
    <resource-ref>
         <res-ref-name>jdbc/quoting</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>SERVLET</res-auth>
    </resource-ref>
</web-app>
 
Y el servlet Main:
 
public class Main extends HttpServlet {
 
    /*CONEXION BASE DE DATOS*/
    private DataSource ds;
    private HttpSession sesion;
 
   /*INICIALIZAR SERVLET. UTILIZAR JNDI PARA BUSCAR UN DataSource*/
   @Override
   public void init(){
        try{
            Context ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("java:comp/env/jdbc/quoting");
        }
        catch(javax.naming.NamingException e){
            System.out.println("Un problema ocurrió mientras se recuperaba un DataSurce");
            System.out.println(e.toString());
        }
    }
...
private boolean autentificar (String _uid, String _pwd){
        Connection conexion = null;
        ResultSet rs = null;
        try{
            conexion = ds.getConnection("xxxx","xxxx");
            Statement s = conexion.createStatement();
            rs = s.executeQuery("SELECT * FROM usuario WHERE id_usuario='"+_uid+"' and contraseña='"+_pwd+"'");
            return (rs.next());
        }
        catch(java.sql.SQLException e){
            System.out.println("Un problema ocurrió mientras se accdía a la base de datos");
            System.out.println(e.toString());
        }
        finally{
            try{
                conexion.close();
            }
            catch (SQLException e){
                System.out.println("Un problema ocurrió mientras se cerraba la conexión a la base de datos");
                System.out.println(e.toString());
            }
        }
        return false;
}
 
Mi problema es el siguiente: Cuando se ejecuta el init() no da ningun error, pero mas tarde cuando llega al metodo autentificar y se ejecuta la instruccion conexion = ds.getConnection("xxxx","xxxx"); me salta al conexion.close() directamente.
¿Por qué? ?Qué está mal?
Gracias de antemano 
   
 


