我有這樣值java.sql.SQLException:在空的結果不合法的操作設置
String sql_kode_kategori = "select kategori from data_kategori \n" +
"where kode_kategori = ?";
try{
pst = (PreparedStatement) koneksiMySQL.GetConnection().prepareStatement(sql_kode_kategori);
pst.setString(1, (String)cbKategori.getSelectedItem());
rst2 = pst.executeQuery();
rst2.next();
stat = (Statement) koneksiMySQL.GetConnection().createStatement();
String sql_insert = "INSERT INTO data_pasal VALUES ('"+jTPasal.getText() + "','"+jTIsi_Pasal.getText()+"'"
+ ",'"+jTHukuman.getText()+"','"+jTDenda.getText()+"','"+rst2.getString(1)+"')";
stat.executeUpdate(sql_insert);
javax.swing.JOptionPane.showMessageDialog(null, "Data CES Berhasil Ditambahkan");
ClearField();
TampilTabel();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
我試圖讓kode_kategori與駕駛員學校,但這個錯誤出現代碼,請幫我
首先要做的事:停止將值直接插入到SQL中。正如你已經爲查詢部分所做的那樣,使用參數化SQL。 –
如果rst2.next()返回false,則不會有rst2.getString(1)的數據。你需要檢查結果,如果(rst2.next()){ – Jan
你可以給我一些源代碼的例子嗎? –