Para conectar a una base de datos necesitamos un driver, que es un fichero que debe estar en el path del proyecto en /WEB-INF/lib.
<Context> <resource name="jdbc/dad2" auth="Container" type="javax.sql.DataSource" <!--Name: TipoDeRecurso/NombreAsignado--> maxActive="50" maxIdle ="30"naxWait="10000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" uri="jdbc.mysql://localhost:3306/dad"/> </Context>
public class Control extends HttpServlet{ private static final long serialVersionUID = 1L; public static final String PRM_ACCION = "PRM_ACCION_CONTROL"; private Hashtable<String, Accion> hashAcciones=null; private static Factory factory = null; public void init() throws ServletException{ system.out.println("Iniciando..."); PrepareStatement ps = null; resultSet rs = null; try{ Connection con = Control.ds.getConnection(); ps = con.prepareStatement ("SELECT * FROM ACTIONS"); rs = ps.executeQuery; Action Accion = null; this.hashAcciones = new Hashtable<String, Accion>(); while(rs.next()){ accion = (Accion)Class.forName(rs.getString("class")).newInstance(); String id = res.getString("id"); System.out.println(id + "" + accion); this.hashAcciones.put(id, accion); } }catch(SQLException e){ System.out.println("error" + e.toString()); } catch(InstantActionException e){ e.printStackTrace(); } catch(IllegalAccessException e){ e.printStackTrace(); } catch(ClassNotFoundException e){ e.printStackTrace(); } finally { try{ if (rs != null) rs.close(); if (ps != null) ps.close(); } catch (SQLException e){ e.printStackTrace(); } } System.Out.Println("[OK]"); } } protected void doGet(HttpServletRequest request, httpServlet Response response){ }