Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. public class MBiblioteca {
  2.    
  3.     private String autor;
  4.    
  5.     public MBiblioteca(String autor){
  6.             this.autor = autor ;
  7.     }
  8.    
  9.     public MAutor getAutor(){
  10.         Connection conexion= DriverManager.getConnection(
  11.         "jdbc:derby://localhost:1527/biblioteca",
  12.         "app",
  13.         "app");
  14.         ResultSet resultado = conexion.createStatement.executeQuerry(
  15.         "SELECT idAutor FROM Autores WHERE nombre="+autor );
  16.         if (resultado.hasNext() ){
  17.         int idAutor = resultado.getInt( "idAutor");
  18.         return new MAutor(idAutor);
  19.         } else return null;
  20.     }
  21.  
  22. }
  23.  
  24. public class MAutor {
  25.    
  26.     private int idAutor;
  27.    
  28.     public MAutor ( int idAutor ){
  29.         this.idAutor= idAutor;
  30.     }
  31.     public String getNombre(){
  32.         Connection conexion= DriverManager.getConnection(
  33.         "jdbc:derby://localhost:1527/biblioteca",
  34.         "app",
  35.         "app");
  36.         ResultSet resultado = conexion.createStatement.executeQuerry(
  37.         "SELECT nombre FROM Autores WHERE idAutor="+autor );
  38.         if (resultado.hasNext() ){
  39.         String nombre = resultado.getString( "nombre");
  40.         return new MAutor( "nombre" );
  41.         } else return null;
  42.     }
  43.    
  44.     public ArrayList<MLibros> getMLibros (){
  45.         Connection conexion= DriverManager.getConnection(
  46.         "jdbc:derby://localhost:1527/biblioteca",
  47.         "app",
  48.         "app");
  49.         ResultSet resultado = conexion.createStatement.executeQuerry(
  50.         "SELECT idLibro FROM LibrosAutores WHERE idAutor="+autor );
  51.        
  52.         Arraylist<MLibros> lista = new ArrayList<MLibros>();
  53.         while (resultado.hasNext() ){
  54.             lista.add(new Mlibro(resultado.getInt("idLibro")));
  55.         }
  56.         return lista;
  57.     }
  58.  
  59. }
  60.  
  61. public class MLibro {
  62.    
  63.     private int idLibro;
  64.    
  65.     public MLibro ( int idLibro ){
  66.         this.idLibro= idLibro;
  67.     }
  68.    
  69.     public String getNombre(){
  70.         Connection conexion= DriverManager.getConnection(
  71.         "jdbc:derby://localhost:1527/biblioteca",
  72.         "app",
  73.         "app");
  74.         ResultSet resultado = conexion.createStatement.executeQuerry(
  75.         "SELECT nombre FROM Libros WHERE idLibro="+idLibro );
  76.         if (resultado.hasNext() ){
  77.         String nombre = resultado.getString( "nombre");
  78.         return new MAutor( "nombre" );
  79.         } else return null;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement