Retrieve name of mysql tables

0

I would like to retrieve the name of my tables in java with mysql database. I do not know if it is correct I get a hashcode: (1) model.Campanhas@b5cca49 (2) model.Campanhas@5c369e04

 public ArrayList<Object>  nameTables(){
    try {
        String SQL = "SHOW tables";
        PreparedStatement ps = dataSource.getConexao().prepareStatement(SQL);
        ResultSet rs = ps.executeQuery();
        System.out.println("TABELAS CONSULTADAS COM SUCESSO");
        ArrayList<Object> lista = new ArrayList<>();
        while(rs.next()){
           Pedidos pedidos = new Pedidos();
           pedidos.setNomePedidos(rs);
           lista.add(pedidos);
        }
        rs.close();
        return lista;
     } catch (SQLException ex) {
        System.err.println("ERRO AO PESQUISAR TABELAS: "+ex);
    }
    catch (Exception ex){
        System.err.println("ERRO GERAL AO PESQUISAR TABELA: "+ex);
    }
    return null;
}
    
asked by anonymous 10.06.2018 / 03:22

1 answer

2

When writing the list you are displaying the reference to the ResultSet, not the name of the table, because in the pedidos.setNomePedidos(rs); excerpt you are passing through the entire object parameter. To work, you should pedidos.setNomePedidos(rs.getString(1)); .

To better understand the getString command, go to the java documentation

    
10.06.2018 / 13:56