betoesquivel

AMSS Entrega 3 Entidades

Nov 11th, 2014
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.41 KB | None | 0 0
  1. package entidades;
  2. import java.sql.*;
  3. import java.io.*;
  4.  
  5. public class Articulo {
  6.  
  7.     public int id;
  8.     public String titulo;
  9.     public String contenido;
  10.     public Date fechaP;
  11.     public Date fechaE;
  12.     private transient Conexion conn;
  13.  
  14.     public Articulo(int i, String t, String c, Date p, Date e) {
  15.         this.id = i;
  16.         this.titulo = t;
  17.         this.contenido = c;
  18.         this.fechaP = p;
  19.         this.fechaE = e;
  20.     }
  21.  
  22.     public Articulo(Conexion c){
  23.         this.conn = c;
  24.  
  25.     }
  26.  
  27.  
  28.     public boolean setArticulo(Articulo a) {
  29.         int i = a.id;
  30.         String t = a.titulo;
  31.         String c = a.contenido;
  32.         Date fP = a.fechaP;
  33.         Date fE = a.fechaE;
  34.  
  35.         try {
  36.             String s = "UPDATE articulo SET id = " + i + ", titulo = " + t + ", contenido = " + c + ", fechaPublicacion = " + fP + ", fechaEscritura = " + fE +" WHERE id = " + i;
  37.             conn.stmt.executeUpdate(s);
  38.  
  39.         }catch (SQLException e) {System.out.println ("Cannot update Articulo" + e); return false;}
  40.         return true;
  41.     }
  42.        public Articulo getArticulo(int id){
  43.         try {
  44.             conn.stmt.executeQuery ("SELECT id, titulo, contenido, fechaPublicacion, FechaEscritura FROM articulo WHERE id = " + id);
  45.             ResultSet rs = conn.stmt.getResultSet();
  46.             if (rs.next()) { //Va al primer registro si lo hay
  47.                 int nArt = rs.getInt ("id");
  48.                 String titulo = rs.getString("titulo");
  49.                 String contenido =  rs.getString("contenido");
  50.                 Date fPub = rs.getDate("fechaPub");
  51.                 Date fEsc = rs.getDate("fechaEsc");
  52.                 rs.close();
  53.                 Articulo resultado = new Articulo(nArt, titulo, contenido, fPub, fEsc);
  54.                 return( resultado );
  55.             }else{ return null;}
  56.             } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  57.         return null;
  58.        }
  59.  
  60.        public boolean agregar(int id, String titulo, String contenido, Date fechaPub, Date fechaEsc){
  61.           try {
  62.          String s = "INSERT INTO articulo (id, titulo, contenido, fechaPublicacion, FechaEscritura)" +
  63.                    " VALUES ("+ id + " , '" + titulo + " , '" + contenido + "', " + fechaPub + "', " + fechaEsc + " )";
  64.          System.out.println(s);
  65.          conn.stmt.executeUpdate(s);
  66.  
  67.           }catch (SQLException e) { System.out.println ("Cannot update Articulo" + e ); return false;}
  68.         return true;
  69.        }
  70.  
  71.     public boolean deleteArticulo(int id){
  72.           try {
  73.          String s = "DELETE FROM articulo WHERE id = " + id;
  74.          System.out.println(s);
  75.          conn.stmt.executeUpdate(s);
  76.  
  77.           }catch (SQLException e) { System.out.println ("Cannot delete Articulo" + e ); return false;}
  78.         return true;
  79.        }
  80.  
  81.  
  82.  
  83. }
  84. package entidades;
  85. import java.sql.*;
  86. import java.io.*;
  87.  
  88. public class Autor {
  89.  
  90.     public int id;
  91.     public String nombre;
  92.     public Date fechaUltPub;
  93.     private transient Conexion conn;
  94.  
  95.     public Autor(int i, String nom, Date p) {
  96.         this.id = i;
  97.         this.nombre = nom;
  98.         this.fechaUltPub = p;
  99.     }
  100.  
  101.     public Autor(Conexion c){
  102.         this.conn = c;
  103.     }
  104.  
  105.     public boolean setAutor(Autor a) {
  106.         int i;
  107.         String n;
  108.         Date f;
  109.  
  110.         i = a.id;
  111.         n = a.nombre;
  112.         f = a.fechaUltPub;
  113.  
  114.         try {
  115.             String s = "UPDATE autor SET id = " + i + ", nombre = " + n + ", fechaUltimaPublicacion = " + f+ " WHERE id = " + i;
  116.             conn.stmt.executeUpdate(s);
  117.  
  118.         }catch (SQLException e) {System.out.println ("Cannot update Autor" + e); return false;}
  119.         return true;
  120.     }
  121.  
  122.  
  123.     public Autor getAutor(int id){
  124.         try {
  125.             conn.stmt.executeQuery ("SELECT id, nombre, fechaUltimaPublicacion FROM autor WHERE id = " + id);
  126.             ResultSet rs = conn.stmt.getResultSet();
  127.             if (rs.next()) { //Va al primer registro si lo hay
  128.                 int nAut = rs.getInt ("id");
  129.                 String nom = rs.getString("nombre");
  130.                 Date fUltPub = rs.getDate("fechaUltimaPublicacion");
  131.                 rs.close();
  132.                 Autor resultado = new Autor(nAut, nom, fUltPub);
  133.                 return( resultado );
  134.             }else{ return null;}
  135.             } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  136.         return null;
  137.     }
  138.  
  139.     public boolean agregar(int id, String nom, Date fechaUltPub){
  140.         try {
  141.              String s = "INSERT INTO autor (id, nombre, fechaUltimaPublicacion)" +
  142.                    " VALUES ("+ id + " , '" + nom + "', " + fechaUltPub + " )";
  143.              System.out.println(s);
  144.              conn.stmt.executeUpdate(s);
  145.  
  146.         }catch (SQLException e) { System.out.println ("Cannot update Autor" + e ); return false;}
  147.         return true;
  148.     }
  149.  
  150.     public boolean deleteAutor(int id){
  151.         try {
  152.              String s = "DELETE FROM autor WHERE id = " + id;
  153.              System.out.println(s);
  154.              conn.stmt.executeUpdate(s);
  155.  
  156.         }catch (SQLException e) { System.out.println ("Cannot delete Autor" + e ); return false;}
  157.         return true;
  158.     }
  159.  
  160.  
  161.  
  162. }
  163. package entidades;
  164. import java.sql.*;
  165.  
  166. public class AutorArticulo {
  167.    public int idAutor;
  168.    public int idArticulo;
  169.    private transient Conexion conn;
  170.  
  171.  
  172.    public AutorArticulo(Conexion co){ this.conn = co; }
  173.  
  174.    public AutorArticulo(int idAutor, int idArticulo){
  175.           this.idAutor = idAutor;
  176.           this.idArticulo = idArticulo;
  177.        }
  178.  
  179.    public AutorArticulo getAutorArticulo(int idAutor, int idArticulo){
  180.       try {
  181.          conn.stmt.executeQuery ("SELECT * FROM autorArticulo WHERE idAutor = " + idAutor +" AND idArticulo = "+idArticulo);
  182.          ResultSet rs = conn.stmt.getResultSet();
  183.          if (rs.next()) { //Va al primer registro si lo hay
  184.              this.idArticulo = rs.getInt("idArticulo");
  185.               this.idAutor = rs.getInt("idAutor");
  186.             rs.close();
  187.             return(this);
  188.          }else{ return null;}
  189.       } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  190.       return null;
  191.    }
  192.  
  193.    public boolean addAutorArticulo(AutorArticulo aa){
  194.       try {
  195.           conn.stmt.executeUpdate ("INSERT INTO autorArticulo(idAutor, idArticulo) VALUES('"+aa.idAutor+"','"+aa.idArticulo+"')");
  196.       } catch (SQLException e) {System.out.println ("Cannot getAutorArticulo()" + e);
  197.       return false;
  198.       }
  199.       return true;
  200.    }
  201.  
  202.    public boolean deleteAutorArticulo(AutorArticulo aa){
  203.           try {
  204.               conn.stmt.executeUpdate ("delete from autorArticulo where idAutor = "+aa.idAutor+" AND idArticulo = "+aa.idArticulo);
  205.           } catch (SQLException e) {System.out.println ("Cannot setAutorArticulo()" + e);
  206.           return false;
  207.           }
  208.           return true;
  209.        }
  210.  
  211. }
  212. package entidades;
  213. import java.sql.*;
  214.  
  215. public class CartaEditorJefe {
  216.    public int id;
  217.    public int idEditorJefe;
  218.    public String contenido;
  219.    private transient Conexion conn;
  220.  
  221.  
  222.    public CartaEditorJefe(Conexion conn){ this.conn = conn; }
  223.  
  224.    public CartaEditorJefe(int id, int idEditorJefe,  String contenido){
  225.       this.id = id;
  226.       this.idEditorJefe = idEditorJefe;
  227.       this.contenido = contenido;
  228.     }
  229.  
  230.    public CartaEditorJefe getCartaEditorJefe(int id){
  231.       try {
  232.          conn.stmt.executeQuery ("SELECT * FROM cartaEditorJefe WHERE id = " + id);
  233.          ResultSet rs = conn.stmt.getResultSet();
  234.          if (rs.next()) { //Va al primer registro si lo hay
  235.              this.id = rs.getInt("id");
  236.               this.idEditorJefe = rs.getInt("idEditorJefe");
  237.              this.contenido = rs.getString("contenido");
  238.             rs.close();
  239.             return(this);
  240.          }else{ return null;}
  241.       } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  242.       return null;
  243.    }
  244.  
  245.    public boolean setCartaEditorJefe(CartaEditorJefe carta){
  246.       try {
  247.           String s = "UPDATE cartaEditorJefe SET idEditorJefe = " + carta.idEditorJefe + ", SET contenido = " + carta.contenido + " WHERE id = " + carta.id;
  248.           conn.stmt.executeUpdate(s);
  249.       } catch (SQLException e) {System.out.println ("Cannot execute disposicion()" + e);
  250.       return false;
  251.       }
  252.       return true;
  253.    }
  254.  
  255.    public boolean addCartaEditorJefe(CartaEditorJefe carta){
  256.       try {
  257.           conn.stmt.executeUpdate ("INSERT INTO cartaEditorJefe(idEditorJefe, contenido) VALUES('"+carta.idEditorJefe+"','"+carta.contenido+"')");
  258.       } catch (SQLException e) {System.out.println ("Cannot getCartaEditorJefe()" + e);
  259.       return false;
  260.       }
  261.       return true;
  262.    }
  263.  
  264.    public boolean deleteCartaEditorJefe(CartaEditorJefe carta){
  265.           try {
  266.               conn.stmt.executeUpdate ("delete from cartaEditorJefe where id = "+carta.id);
  267.           } catch (SQLException e) {System.out.println ("Cannot setcartaEditorJefe()" + e);
  268.           return false;
  269.           }
  270.           return true;
  271.        }
  272.  
  273. }
  274. package entidades;
  275.  
  276. import java.sql.*;
  277. import java.io.*;
  278. public class Conexion {
  279.    public Connection conn;
  280.    public Statement stmt, stmt2;
  281.  
  282.    public Conexion(){
  283.       try {
  284.         String userName = "root";
  285.         String password = "";
  286.         String url = "jdbc:mysql://localhost/tec";
  287.         Class.forName ("com.mysql.jdbc.Driver").newInstance();
  288.         conn = DriverManager.getConnection (url, userName, password);
  289.         stmt = conn.createStatement();
  290.         stmt2 = conn.createStatement();
  291.       }catch (Exception e) { System.out.println ("Cannot connect to database server"); }
  292.    }
  293. }
  294. package entidades;
  295. import java.sql.*;
  296.  
  297. public class Consejo {
  298.    public int id;
  299.    public String nombre;
  300.    public Date anio;
  301.    private transient Conexion conn;
  302.  
  303.    public Consejo(Conexion co){
  304.       this.conn = co;
  305.    }
  306.  
  307.    public Consejo(int id, String nombre, Date anio){
  308.           this.id = id;
  309.           this.nombre = nombre;
  310.           this.anio = anio;
  311.        }
  312.  
  313.    public Consejo getConsejo(int id){
  314.       try {
  315.          conn.stmt.executeQuery ("SELECT * FROM consejo WHERE id = " + id);
  316.          ResultSet rs = conn.stmt.getResultSet();
  317.          if (rs.next()) { //Va al primer registro si lo hay
  318.              this.id = rs.getInt("id");
  319.               this.nombre = rs.getString("nombre");
  320.              this.anio = rs.getDate("anio");
  321.             rs.close();
  322.             return(this);
  323.          }else{ return null;}
  324.       } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  325.       return null;
  326.    }
  327.  
  328.    public boolean setConsejo(Consejo con){
  329.       try {
  330.           String s = "UPDATE consejo SET nombre = " + con.nombre + ", SET anio = " + con.anio + " WHERE id = " + con.id;
  331.           conn.stmt.executeUpdate(s);
  332.       } catch (SQLException e) {System.out.println ("Cannot execute disposicion()" + e);
  333.       return false;
  334.       }
  335.       return true;
  336.    }
  337.  
  338.    public boolean addConsejo(Consejo con){
  339.       try {
  340.           conn.stmt.executeUpdate ("INSERT INTO consejo(nombre, anio) VALUES('"+con.nombre+"','"+con.anio+"')");
  341.       } catch (SQLException e) {System.out.println ("Cannot getConsejo()" + e);
  342.       return false;
  343.       }
  344.       return true;
  345.    }
  346.  
  347.    public boolean deleteConsejo(Consejo con){
  348.           try {
  349.               conn.stmt.executeUpdate ("delete from consejo where id = "+con.id);
  350.           } catch (SQLException e) {System.out.println ("Cannot setConsejo()" + e);
  351.           return false;
  352.           }
  353.           return true;
  354.        }
  355.  
  356. }
  357. package entidades;
  358. import java.sql.*;
  359. import java.io.*;
  360.  
  361. public class EditorJefe {
  362.    public int id, idConsejo;
  363.    public String nombre;
  364.    private transient Conexion conn;
  365.  
  366.    public EditorJefe(Conexion c){
  367.       this.conn = c;
  368.    }
  369.  
  370.    public EditorJefe(int id, int idConsejo, String nombre) {
  371.        this.id = id;
  372.        this.idConsejo = idConsejo;
  373.        this.nombre = nombre;
  374.    }
  375.  
  376.    public EditorJefe getEditorJefe(int id) {
  377.        try {
  378.            conn.stmt.executeQuery ("SELECT * FROM editorJefe WHERE id = " + id);
  379.            ResultSet rs = conn.stmt.getResultSet();
  380.            if (rs.next()) { //Va al primer registro si lo hay
  381.                this.id = rs.getInt ("id");
  382.                this.idConsejo = rs.getInt ("idConsejo");
  383.                this.nombre = rs.getString ("nombre");
  384.                rs.close();
  385.                return this;
  386.            }else{ return null;}
  387.        }catch (SQLException e) {
  388.            System.out.println(e); return null;
  389.        }
  390.    }
  391.  
  392.    public boolean setEditorJefe(EditorJefe j) {
  393.        try{
  394.            conn.stmt.executeUpdate ("UPDATE editorJefe SET idConsejo = " + j.idConsejo + ", nombre = " + j.nombre + " WHERE id = " + j.id);
  395.            return true;
  396.        } catch(SQLException e) {
  397.            return false;
  398.        }
  399.    }
  400.  
  401.    public boolean insertEditorJefe(EditorJefe j) {
  402.        try{
  403.            conn.stmt.executeUpdate ("INSERT INTO editorJefe (idConsejo,nombre) VALUES (" + j.idConsejo + "," + j.nombre + ")");
  404.            return true;
  405.        } catch(SQLException e) {
  406.            return false;
  407.        }
  408.    }
  409.  
  410.    public boolean deleteEditorJefe(int id) {
  411.        try{
  412.            conn.stmt.executeUpdate ("DELETE FROM editorJefe WHERE id = " + id);
  413.            return true;
  414.        } catch(SQLException e) {
  415.            return false;
  416.        }
  417.    }
  418. }
  419. package entidades;
  420. import java.sql.*;
  421.  
  422. public class Guru {
  423.    public int id;
  424.    public String nombre;
  425.    private transient Conexion conn;
  426.  
  427.    public Guru(Conexion co){
  428.       this.conn = co;
  429.    }
  430.  
  431.    public Guru(int id, String nombre){
  432.           this.id = id;
  433.           this.nombre = nombre;
  434.        }
  435.  
  436.    public Guru getGuru(int id){
  437.       try {
  438.          conn.stmt.executeQuery ("SELECT * FROM guru WHERE id = " + id);
  439.          ResultSet rs = conn.stmt.getResultSet();
  440.          if (rs.next()) { //Va al primer registro si lo hay
  441.              this.id = rs.getInt("id");
  442.               this.nombre = rs.getString("nombre");
  443.             rs.close();
  444.             return(this);
  445.          }else{ return null;}
  446.       } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  447.       return null;
  448.    }
  449.  
  450.    public boolean setGuru(Guru gur){
  451.       try {
  452.           String s = "UPDATE guru SET nombre = " + gur.nombre + " WHERE id = " + gur.id;
  453.           conn.stmt.executeUpdate(s);
  454.       } catch (SQLException e) {System.out.println ("Cannot execute disposicion()" + e);
  455.       return false;
  456.       }
  457.       return true;
  458.    }
  459.  
  460.    public boolean addGuru(Guru gur){
  461.       try {
  462.           conn.stmt.executeUpdate ("INSERT INTO guru(nombre) VALUES('"+gur.nombre+")");
  463.       } catch (SQLException e) {System.out.println ("Cannot addGuru()" + e);
  464.       return false;
  465.       }
  466.       return true;
  467.    }
  468.  
  469.    public boolean deleteGuru(Guru gur){
  470.           try {
  471.               conn.stmt.executeUpdate ("delete from guru where id = "+gur.id);
  472.           } catch (SQLException e) {System.out.println ("Cannot setGuru()" + e);
  473.           return false;
  474.           }
  475.           return true;
  476.        }
  477.  
  478. }
  479. package entidades;
  480. import java.sql.*;
  481. import java.io.*;
  482.  
  483. public class Juez {
  484.    public int id, idConsejo;
  485.    public String nombre;
  486.    private transient Conexion conn;
  487.  
  488.    public Juez(Conexion c){
  489.       this.conn = c;
  490.    }
  491.  
  492.    public Juez(int id, int idConsejo, String nombre) {
  493.        this.id = id;
  494.        this.idConsejo = idConsejo;
  495.        this.nombre = nombre;
  496.    }
  497.  
  498.    public Juez getJuez(int id) {
  499.        try {
  500.            conn.stmt.executeQuery ("SELECT * FROM juez WHERE id = " + id);
  501.            ResultSet rs = conn.stmt.getResultSet();
  502.            if (rs.next()) { //Va al primer registro si lo hay
  503.                this.id = rs.getInt ("id");
  504.                this.idConsejo = rs.getInt ("idConsejo");
  505.                this.nombre = rs.getString ("nombre");
  506.                rs.close();
  507.                return this;
  508.            }else{ return null;}
  509.        } catch (SQLException e) {
  510.            System.out.println(e); return null;
  511.        }
  512.    }
  513.  
  514.    public boolean setJuez(Juez j) {
  515.        try{
  516.            conn.stmt.executeUpdate ("UPDATE juez SET idConsejo = " + j.idConsejo + ", nombre = " + j.nombre + " WHERE id = " + j.id);
  517.            return true;
  518.        } catch(SQLException e) {
  519.            return false;
  520.        }
  521.    }
  522.  
  523.    public boolean insertJuez(Juez j) {
  524.        try{
  525.            conn.stmt.executeUpdate ("INSERT INTO juez (idConsejo,nombre) VALUES (" + j.idConsejo + "," + j.nombre + ")");
  526.            return true;
  527.        } catch(SQLException e) {
  528.            return false;
  529.        }
  530.    }
  531.  
  532.    public boolean deleteJuez(int id) {
  533.        try{
  534.            conn.stmt.executeUpdate ("DELETE FROM juez WHERE id = " + id);
  535.            return true;
  536.        } catch(SQLException e) {
  537.            return false;
  538.        }
  539.    }
  540. }
  541. package entidades;
  542. import java.sql.*;
  543.  
  544. public class PublicacionGuru {
  545.    public int idGuru;
  546.    public int idPub;
  547.    public Date fechaEnvio;
  548.    private transient Conexion conn;
  549.  
  550.    public PublicacionGuru(Conexion conn){ this.conn = conn; }
  551.  
  552.    public PublicacionGuru(int idGuru, int idPub, Date fechaEnvio){
  553.        this.idGuru = idGuru;
  554.        this.idPub = idPub;
  555.        this.fechaEnvio = fechaEnvio;
  556.    }
  557.  
  558.    public PublicacionGuru getPublicacionGuru(int idG, int idP){
  559.        String s = "SELECT * FROM guruPub WHERE" +
  560.            " idGuru = " + idG + " and idPub = " + idP;
  561.        try {
  562.            conn.stmt.executeQuery(s);
  563.            ResultSet rs = conn.stmt.getResultSet();
  564.            if(rs.next()){
  565.                this.fechaEnvio = rs.getDate("fechaEnvio");
  566.            }else{
  567.                return null;
  568.            }
  569.        }catch(SQLException e){
  570.            System.out.println(e);
  571.            return null;
  572.        }
  573.        return new PublicacionGuru(idG, idP, this.fechaEnvio);
  574.    }
  575.  
  576.    public boolean setPublicacionGuru(PublicacionGuru pg){
  577.        String s = "UPDATE guruPub " +
  578.                   "SET idGuru =  " + pg.idGuru + ", idPub = " + pg.idPub +
  579.                   ", fechaEnvio = " + pg.fechaEnvio +
  580.                   "WHERE idGuru = " + pg.idGuru + " and idPub = " + pg.idPub;
  581.        try {
  582.            conn.stmt.executeUpdate(s);
  583.        }catch(SQLException e){
  584.            System.out.println(e);
  585.            return false;
  586.        }
  587.        return true;
  588.    }
  589.  
  590.    public boolean addPublicacionGuru(PublicacionGuru pg){
  591.        String s = "INSERT INTO guruPub " +
  592.                   "VALUES (" + pg.idGuru + "," + pg.idPub + "," + pg.fechaEnvio + ") ";
  593.        try {
  594.            conn.stmt.executeUpdate(s);
  595.        }catch(SQLException e){
  596.            System.out.println(e);
  597.            return false;
  598.        }
  599.        return true;
  600.    }
  601.  
  602.    public boolean deletePublicacionGuru(int idG, int idP){
  603.        String s = "DELETE FROM guruPub " +
  604.                   "WHERE idGuru = " + idG + " and idPub = " + idP;
  605.        try {
  606.            conn.stmt.executeUpdate(s);
  607.        }catch(SQLException e){
  608.            System.out.println(e);
  609.            return false;
  610.        }
  611.        return true;
  612.    }
  613. }
  614.  
  615.  
  616. package entidades;
  617. import java.sql.*;
  618. import java.io.*;
  619.  
  620. public class Publicacion {
  621.     public int id;
  622.     public int idJefe;
  623.     public int idCarta;
  624.     private transient Conexion conn;
  625.  
  626.     public Publicacion(int i, int ij, int ic) {
  627.         this.id = i;
  628.         this.idJefe = ij;
  629.         this.idCarta = ic;
  630.     }
  631.  
  632.     public Publicacion(Conexion c){
  633.         this.conn = c;
  634.  
  635.     }
  636.  
  637.     public boolean setPublicacion(Publicacion a) {
  638.         int i;
  639.         int ij;
  640.         int ic;
  641.  
  642.         i = a.id;
  643.         ij = a.idJefe;
  644.         ic = a.idCarta;
  645.  
  646.         try {
  647.             String s = "UPDATE publicacion SET id = " + i + ", idJefe = " + ij + ", idCarta = " + ic + " WHERE id = " + i;
  648.             conn.stmt.executeUpdate(s);
  649.  
  650.         }catch (SQLException e) {System.out.println ("Cannot update Publicacion" + e); return false;}
  651.         return true;
  652.     }
  653.  
  654.  
  655.     public Publicacion getPublicacion(int id){
  656.         try {
  657.             conn.stmt.executeQuery ("SELECT id, idJefe, idCarta FROM publicacion WHERE id = " + id);
  658.             ResultSet rs = conn.stmt.getResultSet();
  659.             if (rs.next()) { //Va al primer registro si lo hay
  660.                 int i = rs.getInt ("id");
  661.                 int ij = rs.getInt("idJefe");
  662.                 int ic = rs.getInt("idCarta");
  663.                 rs.close();
  664.                 Publicacion resultado = new Publicacion(i, ij, ic);
  665.                 return( resultado );
  666.             }else{ return null;}
  667.             } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  668.         return null;
  669.     }
  670.  
  671.     public boolean agregar(int id, String nom, Date fechaUltPub){
  672.         try {
  673.              String s = "INSERT INTO publicacion (id, idJefe, idCarta)" +
  674.                    " VALUES ("+ id + " , '" + idJefe + "', " + idCarta + " )";
  675.              System.out.println(s);
  676.              conn.stmt.executeUpdate(s);
  677.  
  678.         }catch (SQLException e) { System.out.println ("Cannot update Publiacion" + e ); return false;}
  679.         return true;
  680.     }
  681.  
  682.     public boolean deletePublicacion(int id){
  683.         try {
  684.              String s = "DELETE FROM publicacion WHERE id = " + id;
  685.              System.out.println(s);
  686.              conn.stmt.executeUpdate(s);
  687.  
  688.         }catch (SQLException e) { System.out.println ("Cannot delete Publiacion" + e ); return false;}
  689.         return true;
  690.     }
  691.  
  692.  
  693.  
  694. }
  695. package entidades;
  696. import java.sql.*;
  697. import java.io.*;
  698.  
  699. public class PuestoRevistas {
  700.  
  701.     public int id;
  702.     public String direccion;
  703.     private transient Conexion conn;
  704.  
  705.     public PuestoRevistas(int i, String d) {
  706.         this.id = i;
  707.         this.direccion = d;
  708.  
  709.     }
  710.  
  711.     public PuestoRevistas(Conexion c){
  712.         this.conn = c;
  713.  
  714.     }
  715.  
  716.     public boolean setPuestoRevistas(PuestoRevistas a) {
  717.         int i;
  718.         String d;
  719.  
  720.         i = a.id;
  721.         d = a.direccion;
  722.  
  723.         try {
  724.             String s = "UPDATE puestoRevistas SET id = " + i + ", direccion = " + d + " WHERE id = " + i;
  725.             conn.stmt.executeUpdate(s);
  726.         }catch (SQLException e) {System.out.println ("Cannot update PuestoRevistas" + e); return false;}
  727.         return true;
  728.  
  729.     }
  730.  
  731.  
  732.     public PuestoRevistas getPuestoRevistas(int id){
  733.         try {
  734.             conn.stmt.executeQuery ("SELECT id, direccion FROM puestoRevistas WHERE id = " + id);
  735.             ResultSet rs = conn.stmt.getResultSet();
  736.             if (rs.next()) { //Va al primer registro si lo hay
  737.                 int i = rs.getInt ("id");
  738.                 String d = rs.getString("direccion");
  739.                 rs.close();
  740.                 PuestoRevistas resultado = new PuestoRevistas(i, d);
  741.                 return( resultado );
  742.             }else{ return null;}
  743.             } catch (SQLException e) {System.out.println("Excepcion en validar " + e); }
  744.         return null;
  745.     }
  746.  
  747.     public boolean agregar(int i, String d){
  748.         try {
  749.              String s = "INSERT INTO puestoRevistas (id, direccion)" +
  750.                    " VALUES ("+ i + " , '" + d + " )";
  751.              System.out.println(s);
  752.              conn.stmt.executeUpdate(s);
  753.         }catch (Exception e) { System.out.println ("Cannot update PuestoRevistas" + e ); return false; }
  754.         return true;
  755.     }
  756.  
  757.     public boolean deletePuestoRevistas(int id){
  758.         try {
  759.              String s = "DELETE FROM puestoRevistas WHERE id = " + id;
  760.              System.out.println(s);
  761.              conn.stmt.executeUpdate(s);
  762.         }catch (Exception e) { System.out.println ("Cannot delete PuestoRevistas" + e ); return false; }
  763.         return true;
  764.     }
  765.  
  766.  
  767.  
  768.  
  769. }
  770. package entidades;
  771. import java.sql.*;
  772. import java.io.*;
  773.  
  774. public class PuestoRevistasPub {
  775.    public int idPuesto,idPub,cantidadEnviada,cantidadRegresada;
  776.    public Date fechaEnvio,fechaRegreso;
  777.    private transient Conexion conn;
  778.  
  779.    public PuestoRevistasPub(Conexion c){
  780.       this.conn = c;
  781.    }
  782.  
  783.    public PuestoRevistasPub(int idPuesto, int idPub, int cantidadEnviada, int cantidadRegresada, Date fechaRegresada, Date fechaEnvio) {
  784.        this.idPuesto = idPuesto;
  785.        this.idPub = idPub;
  786.        this.fechaEnvio = fechaEnvio;
  787.        this.fechaRegreso = fechaRegreso;
  788.        this.cantidadEnviada = cantidadEnviada;
  789.        this.cantidadRegresada = cantidadRegresada;
  790.    }
  791.  
  792.    public PuestoRevistasPub getPuestoRevistasPub(int id) {
  793.        try {
  794.            conn.stmt.executeQuery ("SELECT * FROM suscriptorPub WHERE idPuesto = " + idPuesto + " and idPub = " + idPub);
  795.            ResultSet rs = conn.stmt.getResultSet();
  796.            if (rs.next()) { //Va al primer registro si lo hay
  797.                this.idPuesto = rs.getInt ("idPuesto");
  798.                this.idPub = rs.getInt ("idPub");
  799.                this.cantidadEnviada = rs.getInt ("cantidadEnviada");
  800.                this.cantidadRegresada = rs.getInt ("cantidadRegresada");
  801.                this.fechaEnvio = rs.getDate ("fechaEnvio");
  802.                this.fechaEnvio = rs.getDate ("fechaRegreso");
  803.                rs.close();
  804.                return this;
  805.            }else{ return null;}
  806.        } catch(SQLException e) {
  807.            System.out.println(e); return null;
  808.        }
  809.    }
  810.  
  811.    public boolean setPuestoRevistasPub(PuestoRevistasPub j) {
  812.        try{
  813.            conn.stmt.executeUpdate ("UPDATE suscriptorPub SET cantidadEnviada = " + j.cantidadEnviada + ", cantidadRegresada = " + j.cantidadRegresada + " fechaEnvio = " + j.fechaEnvio + " fechaRegreso = " + j.fechaRegreso + " WHERE idPuesto = " + j.idPuesto + " and idPub = " + j.idPub);
  814.            return true;
  815.        } catch(SQLException e) {
  816.            return false;
  817.        }
  818.    }
  819.  
  820.    public boolean insertPuestoRevistasPub(PuestoRevistasPub j) {
  821.        try{
  822.            conn.stmt.executeUpdate ("INSERT INTO puestoRevistasPub (idPuesto,idPub,cantidadEnviada,cantidadRegresada,fechaRegreso,fechaEnvio) VALUES (" + j.idPuesto + "," + j.idPub + "," + j.cantidadEnviada + "," + j.cantidadRegresada + "," + j.fechaEnvio + "," + j.fechaRegreso + ")");
  823.            return true;
  824.        } catch(SQLException e) {
  825.            return false;
  826.        }
  827.    }
  828.  
  829.    public boolean deletePuestoRevistasPub(int idPuesto, int idPub) {
  830.        try{
  831.            conn.stmt.executeUpdate ("DELETE FROM puestoRevistasPub WHERE idPuesto = " + idPuesto + " and idPub = " + idPub);
  832.            return true;
  833.        } catch(SQLException e) {
  834.            return false;
  835.        }
  836.    }
  837. }
  838. package entidades;
  839. import java.sql.*;
  840. import java.io.*;
  841.  
  842. public class Subscriptor {
  843.  
  844.     public int id;
  845.     public String nombre;
  846.     public String tipo;
  847.     private transient Conexion conn;
  848.  
  849.     public Subscriptor(int i, String n, String t) {
  850.         this.id = i;
  851.         this.nombre = n;
  852.         this.tipo = t;
  853.     }
  854.  
  855.     public Subscriptor(Conexion c){
  856.         this.conn = c;
  857.  
  858.     }
  859.  
  860.     public boolean setSubscriptor(Subscriptor a) {
  861.         int i;
  862.         String n;
  863.         String t;
  864.  
  865.         i = a.id;
  866.         n = a.nombre;
  867.         t = a.tipo;
  868.  
  869.         try {
  870.             String s = "UPDATE subscriptor SET id = " + i + ", nombre = " + n + ", tipo = " + t +  " WHERE id = " + i;
  871.             conn.stmt.executeUpdate(s);
  872.  
  873.         }catch (SQLException e) {System.out.println ("Cannot update Subscriptor" + e); return false;}
  874.  
  875.         return true;
  876.     }
  877.  
  878.  
  879.     public Subscriptor getSubscriptor(int id){
  880.         try {
  881.             conn.stmt.executeQuery ("SELECT id, nombre, tipo FROM subscriptor WHERE id = " + id);
  882.             ResultSet rs = conn.stmt.getResultSet();
  883.             if (rs.next()) { //Va al primer registro si lo hay
  884.                 int i = rs.getInt ("id");
  885.                 String n = rs.getString("nombre");
  886.                 String t = rs.getString("tipo");
  887.                 rs.close();
  888.                 Subscriptor resultado = new Subscriptor(i, n, t);
  889.                 return( resultado );
  890.             }else{ return null;}
  891.             } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  892.         return null;
  893.     }
  894.  
  895.     public boolean agregar(int i, String n, String t){
  896.         try {
  897.              String s = "INSERT INTO subscriptor (id, nombre, tipo)" +
  898.                    " VALUES ("+ i + " , '" + n + "', " + t + " )";
  899.              System.out.println(s);
  900.              conn.stmt.executeUpdate(s);
  901.  
  902.         }catch (SQLException e) { System.out.println ("Cannot update Subscriptor" + e );  return false;}
  903.         return true;
  904.     }
  905.  
  906.     public boolean deleteSubscriptor(int id){
  907.         try {
  908.              String s = "DELETE FROM subscriptor WHERE id = " + id;
  909.              System.out.println(s);
  910.              conn.stmt.executeUpdate(s);
  911.  
  912.         }catch (SQLException e) { System.out.println ("Cannot delete Subscriptor" + e );  return false;}
  913.         return true;
  914.     }
  915.  
  916.  
  917.  
  918. }
  919. package entidades;
  920. import java.sql.*;
  921. import java.io.*;
  922.  
  923. public class SubscriptorPub {
  924.    public int idSub,idPub,costoAdicional;
  925.    public Date fechaEnvio;
  926.    private transient Conexion conn;
  927.  
  928.    public SubscriptorPub(Conexion c){
  929.       this.conn = c;
  930.    }
  931.  
  932.    public SubscriptorPub(int idSub, int idPub, int costoAdicional, Date fechaEnvio) {
  933.        this.idSub = idSub;
  934.        this.idPub = idPub;
  935.        this.costoAdicional = costoAdicional;
  936.        this.fechaEnvio = fechaEnvio;
  937.    }
  938.  
  939.    public SubscriptorPub getSubscriptorPub(int id) {
  940.        try {
  941.            conn.stmt.executeQuery ("SELECT * FROM subscriptorPub WHERE idSub = " + idSub + " and idPub = " + idPub);
  942.            ResultSet rs = conn.stmt.getResultSet();
  943.            if (rs.next()) { //Va al primer registro si lo hay
  944.                this.idSub = rs.getInt ("idSub");
  945.                this.idPub = rs.getInt ("idPub");
  946.                this.costoAdicional = rs.getInt ("costoAdicional");
  947.                this.fechaEnvio = rs.getDate ("fechaEnvio");
  948.                rs.close();
  949.                return this;
  950.            }else{ return null;}
  951.        } catch(SQLException e){
  952.            System.out.println(e); return null;
  953.        }
  954.    }
  955.  
  956.    public boolean setSubscriptorPub(SubscriptorPub j) {
  957.        try{
  958.            conn.stmt.executeUpdate ("UPDATE subscriptorPub SET costoAdicional = " + j.costoAdicional + ", fechaEnvio = " + j.fechaEnvio + " WHERE idSub = " + j.idSub + " and idPub = " + j.idPub);
  959.            return true;
  960.        } catch(SQLException e) {
  961.            return false;
  962.        }
  963.    }
  964.  
  965.    public boolean insertSubscriptorPub(SubscriptorPub j) {
  966.        try{
  967.            conn.stmt.executeUpdate ("INSERT INTO subscriptorPub (idSub,idPub,costoAdicional,fechaEnvio) VALUES (" + j.idSub + "," + j.idPub + "," + j.costoAdicional + "," + j.fechaEnvio + ")");
  968.            return true;
  969.        } catch(SQLException e) {
  970.            return false;
  971.        }
  972.    }
  973.  
  974.    public boolean deleteSubscriptorPub(int idSub, int idPub) {
  975.        try{
  976.            conn.stmt.executeUpdate ("DELETE FROM puestoRevistasPub WHERE idSub = " + idSub + " and idPub = " + idPub);
  977.            return true;
  978.        } catch(SQLException e) {
  979.            return false;
  980.        }
  981.    }
  982. }
  983. package entidades;
  984. import java.sql.*;
  985.  
  986. public class TemaSugerido {
  987.    public int id;
  988.    public int idPub;
  989.    public String tema;
  990.    private transient Conexion conn;
  991.  
  992.  
  993.    public TemaSugerido(Conexion co){
  994.       this.conn = co;
  995.    }
  996.  
  997.    public TemaSugerido(int id, int idPub,  String tema){
  998.           this.id = id;
  999.           this.idPub = idPub;
  1000.           this.tema = tema;
  1001.        }
  1002.  
  1003.    public TemaSugerido getTemaSugerido(int id){
  1004.       try {
  1005.          conn.stmt.executeQuery ("SELECT * FROM temaSugerido WHERE id = " + id);
  1006.          ResultSet rs = conn.stmt.getResultSet();
  1007.          if (rs.next()) { //Va al primer registro si lo hay
  1008.              this.id = rs.getInt("id");
  1009.               this.idPub = rs.getInt("idPub");
  1010.              this.tema = rs.getString("tema");
  1011.             rs.close();
  1012.             return(this);
  1013.          }else{ return null;}
  1014.       } catch (SQLException e) {System.out.println("Excepcion en validar " + e);}
  1015.       return null;
  1016.    }
  1017.  
  1018.    public boolean setTemaSugerido(TemaSugerido tema){
  1019.       try {
  1020.           String s = "UPDATE temaSugerido SET idPub = " + tema.idPub + ", SET tema = " + tema.tema + " WHERE id = " + tema.id;
  1021.           conn.stmt.executeUpdate(s);
  1022.       } catch (SQLException e) {System.out.println ("Cannot execute disposicion()" + e);
  1023.       return false;
  1024.       }
  1025.       return true;
  1026.    }
  1027.  
  1028.    public boolean addTemaSugerido(TemaSugerido tema){
  1029.       try {
  1030.           conn.stmt.executeUpdate ("INSERT INTO temaSugerido(idPub, tema) VALUES('"+tema.idPub+"','"+tema.tema+"')");
  1031.       } catch (SQLException e) {System.out.println ("Cannot getTemaSugerido()" + e);
  1032.       return false;
  1033.       }
  1034.       return true;
  1035.    }
  1036.  
  1037.    public boolean deleteTemaSugerido(TemaSugerido tema){
  1038.           try {
  1039.               conn.stmt.executeUpdate ("delete from temaSugerido where id = "+tema.id);
  1040.           } catch (SQLException e) {System.out.println ("Cannot setTemaSugerido()" + e);
  1041.           return false;
  1042.           }
  1043.           return true;
  1044.        }
  1045.  
  1046. }
Advertisement
Add Comment
Please, Sign In to add comment