Error can not call getNString () when capturing BD values

0

I am developing a small application of a private clinic and to enter the application, I first select the patient's identifier through JComboBox .

Then, I have a method to fill a arrayList with the patients' data to later fill in a form with said data.

The problem I have when filling this array , before filling it I capture all the values of resultset and in the exception I miss this error:

  

can not call getNString () when field's charset isn't UTF-8

I sense that this exception is jumping because some field of BD has a charset different, but I can not find out why.

I am enclosing my current source where the error is occurring:

public void llenarArrayList() throws UnsupportedEncodingException{
    resultSet = mysql.ejecutaConsulta("SELECT * FROM paciente WHERE NUS =" + jcNuss.getSelectedItem());
    int nuss = 0;
    String cadena = "";
    String primerApellido = new String(cadena.getBytes(), "UTF-8");
    String segundoApellido = new String(cadena.getBytes(), "UTF-8");
    String nombre = new String(cadena.getBytes(), "UTF-8");
    int telf = 0;
    Date fechaNacimiento = null;
    Date fechaAlta = null;
    int medicamento = 0;
    try {
        while(resultSet.next()){
            nuss = resultSet.getInt(1);
            nombre = resultSet.getString(2);
            primerApellido = resultSet.getString(3);
            segundoApellido = resultSet.getNString(4);
            telf = resultSet.getInt(5);
            fechaNacimiento = resultSet.getDate(5);
            fechaAlta = resultSet.getDate(6);
            medicamento = resultSet.getInt(7);  
        }

        System.out.println("nus: " + nuss + " Nombre: " + nombre + " apellido: " + primerApellido + " apellido2: " + 
                    segundoApellido + " telf: " + telf + " fechaNacimiento: " + fechaNacimiento + " fechaAlta: " + fechaAlta+
                    " medicam " + medicamento);

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }

thanks in advance.

    
asked by daviserraalonso 02.05.2018 в 20:45
source

1 answer

0

You are using two different recoveries for your rows.

primerApellido = resultSet.getString(3);
segundoApellido = resultSet.getNString(4);

It is important to use the type of method according to the creation of the column. The getString method is normally used to obtain data from cells "CHAR", "VARCHAR", "TEXT", ... in general in cells with one byte per character. While getNString is used for columns of type "NCHAR", "NVARCHAR", ... In general columns that support more than one byte per character.

In your case surely the table is defined with standard coding and the return of segundoApellido should be getString(4)

    
answered by 02.05.2018 / 21:52
source