Foros del Web » Programación para mayores de 30 ;) » Java »

ayuda con procedimientos

Estas en el tema de ayuda con procedimientos en el foro de Java en Foros del Web. buen dia, tengo una clase como la siguiente Código: /* * To change this template, choose Tools | Templates * and open the template in ...
  #1 (permalink)  
Antiguo 25/11/2009, 11:43
 
Fecha de Ingreso: marzo-2006
Mensajes: 194
Antigüedad: 18 años, 1 mes
Puntos: 1
ayuda con procedimientos

buen dia, tengo una clase como la siguiente

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package agenda;

import java.sql.*;
/**
 * Autores: Alexandra Tatiana Rivera
 *          Aura María Carrillo
 *          Jorge Bernal
 *          Mario Andrés Cervantes

 */
public class Usuario {
private String Nombre;
private String Email;
private String Perfil;
private String Usuario;
private String Clave;
private String Estado;
private Connection conexion;
private Statement conecta;
private ResultSet datos;
static String bd = "agenda";
static String login = "root";
static String password = "mancemo";
static String url = "jdbc:mysql://localhost/"+bd;

public Usuario(String Nombre, String Email, String Perfil, String Usuario, String Clave, String Estado) {

        setNombre(Nombre);
        setEmail(Email);
        setPerfil(Perfil);
        setUsuario(Usuario);
        setClave(Clave);
        setEstado(Estado);

    }

    public Usuario() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        conexion=DriverManager.getConnection(url,login,password);
        conecta=conexion.createStatement();
    }

    public ResultSet getClave(){
        try{
            String Consulta="select * from usuarios";
            datos=conecta.executeQuery(Consulta);
            return datos;
        }catch (SQLException ex){
            return null;
        }
    }

    public ResultSet valUsuario(String Clave,String Usuario){
        try{
            String Consulta="select * from usuarios where clave="+Clave+" and usuario="+Usuario+"";
            datos=conecta.executeQuery(Consulta);
            return datos;
        }catch (SQLException ex){
            return null;
        }
    }
    /**
     * @return the Nombre
     */
    public String getNombre() {
        return Nombre;
    }

    /**
     * @param Nombre the Nombre to set
     */
    public void setNombre(String Nombre) {
        this.Nombre = Nombre;
    }

    /**
     * @return the Email
     */
    public String getEmail() {
        return Email;
    }

    /**
     * @param Email the Email to set
     */
    public void setEmail(String Email) {
        this.Email = Email;
    }

    /**
     * @return the Perfil
     */
    public String getPerfil() {
        return Perfil;
    }

    /**
     * @param Perfil the Perfil to set
     */
    public void setPerfil(String Perfil) {
        this.Perfil = Perfil;
    }

    /**
     * @return the Usuario
     */
    public ResultSet getUsuario(String Usuario) {
        try{
            String Consulta="select * from usuarios where usuario="+Usuario+"";
            datos=conecta.executeQuery(Consulta);
            return datos;
        }catch (SQLException ex){
            return null;
        }
    }

    /**
     * @param Usuario the Usuario to set
     */
    public void setUsuario(String Usuario) {
        this.Usuario = Usuario;
    }

    /**
     * @return the Clave
     */
    public ResultSet getClave(String Clave) {
        try{
            String Consulta="select * from usuarios where clave="+Clave+"";
            datos=conecta.executeQuery(Consulta);
            return datos;
        }catch (SQLException ex){
            return null;
        }
    }

    /**
     * @param Clave the Clave to set
     */
    public void setClave(String Clave) {
        this.Clave = Clave;
    }

    /**
     * @return the Estado
     */
    public String getEstado() {
        return Estado;
    }

    /**
     * @param Estado the Estado to set
     */
    public void setEstado(String Estado) {
        this.Estado = Estado;
    }
}
como se puede ver con la funcion getUsuario, deberia retornarme el nombre del campo usuario que coincida con la consulta, si no devolver nulo, en un formulario lo que hago es lo siguiente;

Código:
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        //new formularios.Principal().show();
        String Usuario= user.getText();
        String Clave= pass.getText();
        try{
            Usuario us = new Usuario();
            ResultSet usuario = us.getUsuario(Usuario);
            String use= String.valueOf(us);
            JOptionPane.showMessageDialog(rootPane, use);
            Usuario cla;
            cla = new Usuario();
            cla.getUsuario(Clave);
            String clav= String.valueOf(cla);
            if (Usuario == use)
            {
                new formularios.Principal().show();
                dispose();
            }else
            {
               JOptionPane.showMessageDialog(rootPane, "Usuario no es igual" ); 
            }

        }catch (ClassNotFoundException ex){
            JOptionPane.showMessageDialog(rootPane, "Problemas de Conexion con la base de datos" );
        }catch (SQLException ex){
            JOptionPane.showMessageDialog(rootPane, "Problemas de SQL" );
        }

    }
pero no me funciona el retorno si lo muestro en pantalla muestra algo distinto, no se si es en el retorno de la funcion.

gracias
  #2 (permalink)  
Antiguo 26/11/2009, 02:17
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 8 meses
Puntos: 188
Respuesta: ayuda con procedimientos

Cometes un grave error, metes una clase Usuario y luego una variable tipo String llamada Usuario, el programa se vuelve loco... llama a ese String de otro modo... y trátalo como corresponde en los métodos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:03.