necromancer669 Posted November 23, 2010 Report Share Posted November 23, 2010 quiero hacer un método donde me verifique la existencia del nombre de usuario, para invalidar el registro de nuevos, tengo lo siguiente: public static int usuario_repetido(usuario e){ try { config cn= new config(); ResultSet rs; Connection connection = cn.conectar(); //Select the data from the database String sql = "select count(*) as cero from usuarios where nombre_usuario ='"+e.getNombre_usuario()+"'"; Statement s = connection.createStatement(); s.executeQuery (sql); rs = s.getResultSet(); //if( rs.next()){ int num = rs.getInt("select count(*) as cero from usuarios where nombre_usuario ='"+e.getNombre_usuario()+"'"); return num; //} // return true; }catch(Exception ex){ System.out.println("Exception is ;"+ex); return -1; } } No me resulta, lo que trato de hacer es "contar" los nombre de usuarios, y ver si al menos hay 1 para retonar ese número y luego en el main hacer un if y redireccionar la página. No me funciona, alguién cacha que cambio debo hacer? saludos. Link to comment Share on other sites More sharing options...
gunsroses Posted November 23, 2010 Report Share Posted November 23, 2010 Esto esta MAL!! int num = rs.getInt("select count(*) as cero from usuarios where nombre_usuario ='"+e.getNombre_usuario()+"'"); Esto esta BIEN!! int num = rs.getInt("cero"); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now