package BD;

import gerenciamento_compra.Principal;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Loga {
	static boolean aux;

	public boolean buscar(String login, String pass) throws SQLException {
		try {
			aux = false;			
			Connection con = ConnectionFactory.getConnection();
			PreparedStatement stmt = con
					.prepareStatement("select * from contatos");
			ResultSet rs = stmt.executeQuery();
			while (rs.next()) {
				String log = rs.getString("login");
				String key = rs.getString("pass");
				if (log.contentEquals(login) && key.contentEquals(pass)) {
					Principal.setName(null);
					Principal.setName(login);
					aux = true;
				}
			}
			rs.close();
			stmt.close();
			con.close();
		} catch (SQLException e) {
			return false;
		}
		if (aux) {
			return true;
		}
		return false;
	}
}
