這應該很簡單,我想從KATA_DASAR表中檢索KATA記錄並將其放入名爲kamusKata []的數組中。但我似乎無法寫出正確的代碼,有什麼幫助?預先感謝。 :)將SQL解析爲Java中的數組
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;
}
}
我可以對數據在該數據庫中列和類型什麼的一些更詳細是構造函數完成執行後kamusKata數組的內容? – eabraham