I want to read the data from the mysql table and display it as a table using the JTable. Are there any suggestions how to correctly implement this?

  • Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky

1 answer 1

I have no idea how exactly you are extracting data from the database and what is the table structure in your database, and I don’t see any problems in order to display the two-dimensional array in the JTable, so I will answer with a synthetic example to the question from the header:

import java.util.Map; import java.util.HashMap; import java.util.stream.IntStream; class MapTo2DArray { public static void main(String args[]) { Map<String, String> input = new HashMap<>(); //Забиваем Map данными IntStream.rangeClosed(1, 10) .forEach(i -> input.put(String.format("Key%d", i), String.format("Value %d", i))); //Конвертируем Map в двумерный массив String[][] output = input.entrySet() .stream() .map(entry -> new String[]{entry.getKey(), entry.getValue()}) .toArray(String[][]::new); //Выводим результат for(String[] row : output) { System.out.format("%s = %s\n", row[0], row[1]); } } }