,所以我有這樣的代碼的ResultSet對象Array
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Object[] possibilities=null;
try {
possibilities = getNames();
} catch (Exception ex) {
System.out.println("Thiss error "+ex.getMessage());
}
String s;
// TODO add your handling code here:
s = (String) JOptionPane.showInputDialog(this, "Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
"ham"); // TODO add your handling code here:
}
public Object[] getNames() throws Exception {
Object[] possibilities = null;
int i=0;
rs = ds.getResultSet("SELECT name FROM staff");
possibilities= new Object[rs.getMetaData().getColumnCount()];
System.out.println("Result set has data "+rs.next());
while (rs.next()) {
System.out.println("Data from result set "+rs.getString(1));
possibilities[i] = rs.getObject(1);
System.out.println("Data from array "+possibilities[i]);
i++;
}
return possibilities;
}
,我想在工作人員的數據庫來獲取名稱(字符串)的值,這樣我就可以在JOptionPane的使用它作爲一個選項,但所有當我執行這就是我得到
Result set has data true
Data from result set jana dfjks
Data from array jana dfjks
Data from result set jkdfhjk jfhkjdsf
Thiss error 1
我能做些什麼來得到它擁有超過20個結果數據庫中的所有結果我得到。
通過替換 解決方案= new Object [rs.getMetaData()。getColumnCount()]; 與 Possible = new Object [100];
,但我想我怎麼可以讓它動視結果數返回