Recover mysql tables name

Asked

Viewed 93 times

0

I would like to recover the name of my java tables with mysql database. I don’t know if it’s correct I get a hashcode: (1) model.Campanhas@b 5cca49 (2) model.Campaigns@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;
}

1 answer

2


When writing the list you are displaying the reference to Resultset, not the table name, because in the snippet pedidos.setNomePedidos(rs); you are passing the whole object by parameter. To work, you must do pedidos.setNomePedidos(rs.getString(1));.

To better understand the getString command, access the java documentation https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#getString(int)

  • Thanks, thanks to your reply I got the solution. since other things were also wrong. There when I put what you said already accused the error. Ai just been fixing. Vlw same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.