Advertisement
JVFabia

Untitled

Aug 4th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package org.forge;
  2.  
  3. import java.sql.*;
  4.  
  5. public class PersonajeDAO {
  6.  
  7.     public int contarPelicula(String nombre) throws SQLException {
  8.         Connection conn = ConnectionManager.obtenerConexion();
  9.         int cont = 0;
  10.         PreparedStatement sql = conn.prepareStatement("select count(*) as count from personaje p where p.nombre_actor = ? ;");
  11.         sql.setString(1, nombre);
  12.         ResultSet rs = sql.executeQuery();
  13.         while (rs.next()) {
  14.             cont=rs.getInt("count");
  15.         }
  16.         return cont;
  17.     }
  18.  
  19.     public Personaje obtenerPeliculaPorNombre(String nombre) throws SQLException {
  20.  
  21.         Connection conn = ConnectionManager.obtenerConexion();
  22.  
  23.         PreparedStatement sql = conn.prepareStatement("Select * from dbo.personaje p where p.nombre_actor = ?");
  24.         sql.setString(1, nombre);
  25.         ResultSet rs = sql.executeQuery();
  26.         // con constructor
  27.         rs.next();
  28.         Personaje personaje = new Personaje(rs.getString("nombre_actor"), rs.getString("nombre_pelicula"), rs.getInt("anio"),rs.getString("rol"));
  29. //        Sin Constructor
  30. //        Personaje personaje = new Personaje();
  31. //        while (rs.next()) {
  32. //            personaje.setAnio(rs.getInt("anio"));
  33. //            personaje.setNombre_actor(rs.getString("nombre_actor"));
  34. //            personaje.setNombre_pelicula(rs.getString("nombre_pelicula"));
  35. //            personaje.setRol(rs.getString("rol"));
  36. //        }
  37.  
  38.         return personaje;
  39.  
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement