Olá,estou com dificuldade de colocar uma verificação para duplicidade de login no cadastro.Agora poderia me orientar no que fazer.Obrigado
package dao;
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger;import bean.Usuario;
import connection.ConnectionFactory;public class UsuarioDAO {
public boolean checkLogin(String login, String senha) {
Connection con = ConnectionFactory.getConnection(); PreparedStatement stmt = null; ResultSet rs = null; boolean check = false; try { stmt = con.prepareStatement("SELECT * FROM usuario WHERE login = ? and senha = ?"); stmt.setString(1, login); stmt.setString(2, senha); rs = stmt.executeQuery(); if (rs.next()) { check = true; } } catch (SQLException ex) { Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { ConnectionFactory.closeConnection(con, stmt, rs); } return check;}
private static
String SQL_INSERT = “INSERT INTO usuario (login,senha) VALUES (?, ?);”;public void incluir(Usuario usuario) {
Connection con = ConnectionFactory.getConnection(); PreparedStatement stmt = null; try { stmt = con.prepareStatement(SQL_INSERT); stmt.setString(1, usuario.getLogin()); stmt.setString(2, usuario.getSenha()); stmt.execute(); stmt.close(); } catch (SQLException ex) { throw new RuntimeException(ex); }}
// private static
String VALCAD_SQL = “SELECT login FROM usuario WHERE login =
// ?”;}