From the database you need to get and save the values ​​in a two-dimensional array Object[][] data . It should have (as in the table in the database) 4 columns.

I did this:

  try { con = DriverManager.getConnection(url, user, password); stmt = con.createStatement(); rs = stmt.executeQuery(query); count = 0; while(rs.next()) { count++; } Object[][] data = new Object[count][4]; count = 0; while(rs.next()) { data[count][0] = rs.getString(1); data[count][1] = rs.getString(2); data[count][2] = rs.getString(3); data[count][3] = rs.getString(4); count++; } } catch (SQLException e1) { e1.printStackTrace(); } finally { try { con.close(); } catch(SQLException se) {} try { stmt.close(); } catch(SQLException se) {} try { rs.close(); } catch (SQLException se) {} } 

But JAVA gives NullPointerExeption ! My checks revealed that the values ​​in the array are all NULL .

    1 answer 1

    Add this line before the second cycle. Each time next () is called, the pointer moves to the next element, and therefore at the end it points to nowhere and needs to be reset to the beginning.

      rs.beforeFirst()