Sorry before, I know this question has already been asked and has the solution. But when I try to do the same thing, it doesn't work. I have try the solution from the solved question but doesn't work on mine. I used FocusLost event on my jtextfield, when the focus is lost, it shows the exception messages. please help, thank you.
I'm trying to do exactly the same as this solved question.
here's my FocusLost event as suggested on the link above, and the code is nearly the same.
private void kdbarangTxtFocusLost(java.awt.event.FocusEvent evt) {
try{
java.sql.Connection conn = new Koneksi().konek();
String sql = "select nama_brg from barang where kode_brg = '"+kdbarangTxt.getText().trim()+"'";
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rslt = stmt.executeQuery(sql);
while(rslt.next()){
nmbarangTxt.setText(rslt.getString("kode_brg"));
}rslt.close();
conn.close();
}
catch (SQLException e){
JOptionPane.showMessageDialog(null, "Item not found");
}
}
EDIT
I used stacktrace, and here's the result
java.sql.SQLException: Column 'kode_brg' not found.
here's the screenshot, that column does exist -> My database table
it's solved now as suggested from @newuserua_ext
My mistake was in
rslt.getString("kode_brg")
, it shouldrslt.getString("nama_brg")
nama_brg is the column I'm trying to show in my jTextField.Thank you to all of you who has answered my question. Cheers!