1
Hello, I am printing on the screen the result of a SELECT that I have stored in a resultset object (sql.Resultset). But it comes out "all crooked". I tried to use the " t" between each printed column, but it didn’t help. Below is the section of the method that interests us:
public void selectCargos(String query){
try {
rs = st.executeQuery(query);
System.out.printf("TABELA DE CARGOS\n\n");
while (rs.next()){
System.out.println("ID: " +rs.getInt("id")+ "\t"+ "Nome do cargo: " +rs.getString("nome")+ "\t" + "Nível do cargo: " +rs.getString("nivel"));
PS: This problem only exists if I have only one type of table that I want to print. In a real-life case, where my application will have many "entity" classes, with their respective tables, the ideal is that we use a generic method of printing tables, like the one in this topic here: https://answall.com/questions/2747/usar-a-resultset-em-java-para-imprimir-na-tela-toda-uma-tabela-qualquer/272798#27272798
– Lucas Pletsch