title: Parse SQL to Array in Java
body: <p>This should've been simple, I wanted to retrieve KATA records from KATA_DASAR table and put it into an array named kamusKata[]. But I cannot seem to write the correct code, any help? Thank in advance. :)</p>
  
  <pre><code>package ir;
  
  import java.sql.*;
  
  public class kataDasar {
  private String[] kamusKata;
  private int i=0;
  
  public kataDasar () {
      try {
              //definisi connection
              Connection con = DriverManager.getConnection( "jdbc:derby://localhost:1527/stemming", "admin", "admin" );
              Statement stmt = con.createStatement( );
              //SQL query 
              String SQL = "SELECT KATA FROM KATA_DASAR";
              ResultSet rs = stmt.executeQuery(SQL);
  
              while (rs.next()){
              String hasil = (rs.getString("KATA"));
              setKamusKata(hasil);
              }
  
          } catch (SQLException ex) {
              System.err.println("Connection failed"); //jika connection failed
          }
  };
  
  private void setKamusKata (String kata) {
      kamusKata[i] = kata;
      i++;
  }
  
  public String getKamusKata () {
      return kamusKata;
  }
  }
  </code></pre>