Muestra las diferencias entre dos versiones de la página.
| Próxima revisión | Revisión previa | ||
| dad2:bbdd [2024/04/09 10:32] – creado thejuanvisu | dad2:bbdd [2024/04/09 11:09] (actual) – thejuanvisu | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== Bases de Datos ====== | ====== Bases de Datos ====== | ||
| - | 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. | + | 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. |
| + | <code xml contex.xml> | ||
| + | < | ||
| + | < | ||
| + | maxActive=" | ||
| + | username=" | ||
| + | driverClassName=" | ||
| + | uri=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <code java Control.java> | ||
| + | public class Control extends HttpServlet{ | ||
| + | private static final long serialVersionUID = 1L; | ||
| + | public static final String PRM_ACCION = " | ||
| + | |||
| + | private Hashtable< | ||
| + | private static Factory factory = null; | ||
| + | |||
| + | public void init() throws ServletException{ | ||
| + | system.out.println(" | ||
| + | PrepareStatement ps = null; | ||
| + | resultSet rs = null; | ||
| + | try{ | ||
| + | Connection con = Control.ds.getConnection(); | ||
| + | ps = con.prepareStatement (" | ||
| + | rs = ps.executeQuery; | ||
| + | |||
| + | Action Accion = null; | ||
| + | this.hashAcciones = new Hashtable< | ||
| + | while(rs.next()){ | ||
| + | accion = (Accion)Class.forName(rs.getString(" | ||
| + | String id = res.getString(" | ||
| + | System.out.println(id + "" | ||
| + | this.hashAcciones.put(id, | ||
| + | } | ||
| + | |||
| + | }catch(SQLException e){ | ||
| + | System.out.println(" | ||
| + | } 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(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | protected void doGet(HttpServletRequest request, httpServlet Response response){ | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | {{drawio> | ||