Failed to query javaFx through sql statements

1

Well, I have the problem that I want to get the records of a simple select * from table, but it tells me that it does not get any record

The query code

ConexionBD("eduware", "root", "", "3306");
        Conexion();
                this.conexion = Conexion();
                if(this.conexion!=null){
                    this.stmt = this.conexion.createStatement();
                    rs=this.stmt.executeQuery("SELECT * FROM alumno");
                    JOptionPane.showMessageDialog(null,rs.getRow());
                    if(rs.getRow()!=0){
                        JOptionPane.showMessageDialog(null," Ejecutada Con Exito");
                    }
                    else{
                        JOptionPane.showMessageDialog(null," Ejecutada Sin Exito");
                    }

It does everything except at the moment of the if condition, since at that moment it goes through the part that the query has not been done successfully and the message from rs.getRow is as follows:

So I also put a message to see if it had connected to the database and I set the following:

The table does contain information and data about 6 complete records.

    
asked by David 08.10.2016 в 21:59
source

1 answer

2

It is necessary to move the cursor from the ResultSet to the end to get the number of rows returned by the query

ConexionBD("eduware", "root", "", "3306");
    Conexion();
            this.conexion = Conexion();
            if(this.conexion!=null){
                this.stmt = this.conexion.createStatement();
                rs=this.stmt.executeQuery("SELECT * FROM alumno");
                rs.last();
                JOptionPane.showMessageDialog(null,rs.getRow());
                 /* Return Numero Fila Actual. 
                 como movimos antes al final, será igual al total */
                if(rs.getRow()!=0){
                    JOptionPane.showMessageDialog(null," Ejecutada Con Exito");
                  /* Para mover el cursor al Inicio en el caso que 
                   querramos trabajar con los datos devueltos */
                  rs.beforeFirst();
                }
                else{
                    JOptionPane.showMessageDialog(null," Ejecutada Sin Exito");
                }
    
answered by 08.10.2016 / 22:17
source