Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.forge.project.jdbc.dao;
- import com.forge.project.jdbc.ConnectionManager;
- import com.forge.project.jdbc.dto.Actor;
- import com.forge.project.jdbc.dto.actor;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.LinkedList;
- import java.util.List;
- public class ActorDAO {
- private Connection connection;
- public ActorDAO() throws SQLException {
- this.connection = ConnectionManager.obtenerConexion();
- }
- public Actor obtenerActorPorNombre(String nombre) throws SQLException {
- String sql = "select nombre, genero from actor where nombre=?";
- PreparedStatement ps = connection.prepareStatement(sql);
- ps.setString(1, nombre);
- ResultSet rs = ps.executeQuery();
- if(rs.next()) {
- Actor a = new Actor(rs.getString("nombre"), rs.getString("genero"));
- return a;
- }
- return new Actor("", " ");
- }
- public List<Actor> obtenerActorPorNombreLike(String nombre) throws SQLException {
- String sql = "select nombre, genero from actor where nombre like ?";
- PreparedStatement ps = connection.prepareStatement(sql);
- ps.setString(1, nombre);
- List<Actor> resultado = new LinkedList<>();
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- Actor a = new Actor(rs.getString("nombre"), rs.getString("genero"));
- resultado.add(a);
- }
- return resultado;
- }
- public Actor obtenerActor(String nombre) throws SQLException{
- String sql = "select nombre, genero from actor where nombre = ?";
- PreparedStatement ps = connection.prepareStatement(sql);
- ps.setString(1, nombre);
- ResultSet rs = ps.executeQuery();
- if(rs.next()){
- Actor a = new Actor(rs.getString("nombre"), rs.getString("genero"));
- return a;
- }
- return new Actor("","");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement