Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i think its better to return list of object you trying to get its data, for example if you want to get all students form database, you could make class for that:</p> <pre><code>public final class Student { private int id; private String name; private int age; public Student(int id, String name, int age) { this.id = id; this.name = name; this.age = age; } public int getId() { return this.id; } // other getter methods } </code></pre> <p>then you can retrieve all student in list</p> <pre><code>public List&lt;Student&gt; getAllStudents() throws SQLException { List&lt;Student&gt; students = new ArrayList&lt;Student&gt;(); String select = "SELECT * FROM students"; Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(select); while ( resultSet.next() ) { int id = resultSet.getInt(1); String name = resultSet.getString(2); int age = resultSet.getInt(3); Student student = new Student(id, name, age); students.add(student); } return students; } </code></pre> <p><strong>Edit</strong>: to get the size of result set, you can call resultset.last() then call resultset.getRow(), it was discussed here:</p> <p><a href="https://stackoverflow.com/questions/192078/how-do-i-get-the-size-of-a-java-sql-resultset">How do I get the size of a java.sql.ResultSet?</a></p> <p><a href="https://stackoverflow.com/questions/7808350/how-to-get-a-number-of-rows-a-resultset-contains">How to get a number of rows a ResultSet contains?</a></p> <pre><code>ResultSet resultSet = ps.executeQuery(); int rowcount = 0; if (resultSet.last()) { rowcount = resultSet.getRow(); resultSet.beforeFirst(); } </code></pre> <p>then you can build your 2D array:</p> <pre><code> String[][] result = new String[rowCount][ColumnCount]; int i=0; while (resultSet.next()) { // build result[i] array i++; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload