我新的Java和我有這個問題時,我想,當他登錄到從SQL數據庫獲取數據並顯示它。的Java + SQL的executeQuery和返回結果
sql = "select nom from adherent where id_adherent=3";
try {
pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "here 1");
}
try {
if (rs.next()) {
String sum = rs.getString("select *");
nom.setText(" " + sum);
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "here 2");
}
謝謝。
我懷疑'rs.getString(「select *」)'會有任何成功。 – Berger
你不需要兩個單獨的try catch塊,但是你的實際問題是什麼? –
只需按列名稱(或索引)(如rs.getString(「nom」)或rs.getString(1))獲取數據。另外,最好在您使用數據的同一個try塊中使用ResultSet。 –