Advertisement
Guest User

asdasd

a guest
Oct 16th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package cl.cvalpo.dao;
  7.  
  8. import cl.cvalpo.conexion.Conexion;
  9. import cl.cvalpo.entities.Usuario;
  10. import java.sql.Connection;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13.  
  14. /**
  15.  *
  16.  * @author Esteban Perez
  17.  */
  18. public class DAOUsuario {
  19.  
  20.     public Usuario getUsuario(String username, String password) {
  21.         try {
  22.             Conexion conexion = new Conexion();
  23.             Connection conn = conexion.getConexion();
  24.             String sql = "SELECT username, pass FROM login WHERE username = ? AND pass = ?";
  25.             PreparedStatement ps = conn.prepareStatement(sql);
  26.             ps.setString(1, username);
  27.             ps.setString(2, password);
  28.             ResultSet rs = ps.executeQuery();
  29.  
  30.             Usuario usuario = new Usuario();
  31.  
  32.             while (rs.next()) {
  33.                 usuario.setUsername(rs.getString("username").trim());
  34.                 usuario.setPassword(rs.getString("pass").trim());
  35.             }
  36.  
  37.             conn.close();
  38.             ps.close();
  39.             rs.close();
  40.  
  41.             return usuario;
  42.         } catch (Exception e) {
  43.             throw new RuntimeException(e);
  44.         } finally {
  45.            
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement