Parse SQL to Array in Java

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. :)

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 ({
            String hasil = (rs.getString("KATA"));

        } catch (SQLException ex) {
            System.err.println("Connection failed"); //jika connection failed

private void setKamusKata (String kata) {
    kamusKata[i] = kata;

public String getKamusKata () {
    return kamusKata;


See: ArrayList

trutheality's answer probably won't help you because you're never initializing your array.

You would do something like this:

kamusKata = new ArrayList<String>();

while( {

but I'm not sure what your getKamusKata() method is supposed to do. If you want to return it as a string you should look at this question: Java equivalents of C# String.Format() and String.Join()

alternately have your method do:

StringBuilder sb=new StringBuilder();
for(string kata : kamusKata) {

return sb.toString();


public String getKamusKata () {
    return kamusKata;

is probably the problem. Your method should return a String but you're trying to return a String[].

Need Your Help

Make JSpinner completely numeric

java swing textbox numeric jspinner

I've a Jspinner that can vary from minimum to maximum at steps of 0.1. This is working perfectly fine. Now, I set the editor of JSpinner as NumberEditor as the user can edit the textbox and I want ...

Couldn't see RegionServer in Terminal-LINUX-HBASE

hadoop hbase

I installed hadoop and my HBase is running on top of it. All my deamons in hadoop is up and running. After i started my hbase i could see the HMaster running when i gave the JPS command.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.