I have many tables in the database with different number of fields that need to be JTable in the JTable . The idea is:
private void createUIComponents() { Connection connection; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(connectionString,login,password); String select = "SELECT * FROM printinghousedb.districts"; Vector<String> fields = new Vector(); fields.add("DistrictId"); fields.add("DistrictName"); DistrictsTable = new JTable(data, columnNames); Vector data = new Vector(); data = getTable(connection,select,fields); DistrictsTable = new JTable(data, fields); //ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Π΄ΡΡΠ³ΠΈΡ
ΡΠ°Π±Π»ΠΈΡ... } catch (Exception e) { e.printStackTrace(); } } private Vector[] getTable(Connection connection, String request, Vector fields) throws SQLException { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(request); while (rs.next()) { //... I do not know what to do next, how to form a Vector from ResultSet ?
Update
DistrictsTable = new JTable(data, columnNames); - the extra line remaining from previous attempts. I forgot to remove, I apologize.
Object[][]parameter - Mikhail Vaysman