这应该很简单,我想从 KATA_DASAR 表中检索 KATA 记录并将其放入名为 kamusKata[] 的数组中。但我似乎无法编写正确的代码,有什么帮助吗?预先感谢。:)
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;
}
}