Calculating Random Password using ArrayList and ResultSet in Java

0

Good morning, I have a question, I need to calculate a new password for each patient when I go through this method:

 ps = getConexao().prepareStatement(SQL_VERIFICAR_PROTOCOLOS_PENDENTES); 
            ps.setDate(1, new java.sql.Date(dto.getData().getTime()));
            ps.setDate(2, new java.sql.Date(dto.getData2().getTime()));
            ps.setInt(3, dto.getIdCorp());
            rs = ps.executeQuery();

            while (rs.next()) { // fazendo a Busca pelo ResultSet

           StringBuffer CalcSenha = new StringBuffer();  
           ArrayList<String> lista = new ArrayList<String>();
           lista.add(rs.getString("nome"));
           lista.add(rs.getString("data_nascimento"));
           lista.add...........(pego dados do banco);

                for (int i = 0; i < lista.size(); i++) {
                    CalcSenha.append(lista.lista.get(0));
                    System.out.println("A senha calculada foi:" + CalcSenha);
                }

            }

The calculation is done like this:

  

First letter of the name,   position 7 of the date of birth;   position 1 of the date of birth;   position 9 of the date of birth;   position 1 of the medical record;   age with 3 positions;   Total = 6 characters

I can get this data already with My ResultSet , my doubt is I use the StringBuffer giving append, as I go through and get the first letter of the Patient's Name, the 7th position of the Birth date. ..... ???
Not to achieve, because of the way CalcSenha.append (list.list.get (0)); it pulls the whole name.

    
asked by anonymous 28.03.2017 / 15:01

1 answer

1

To get only the first letter of the name, you can use the subString () method.

Ex:

for (int i = 0; i < lista.size(); i++) {
                CalcSenha.append(lista.lista.get(0).subString(0,0));
                System.out.println("A senha calculada foi:" + CalcSenha);
            }

For the date, you need to convert it to String before, which can be done using SimpleDateFormat:


Date date = lista.lista.get(1);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String text = df.format(date);

    
28.03.2017 / 15:52