I've been trying to get a value from txt1(jtextfield) which is an id in my database. But it keep saying java.lang.NullPointerException. Here is the code:
public void harga()
{
try {
stat = con.createStatement();
String query = "SELECT harga from obat WHERE ID = '"+ Integer.valueOf(txt1.getText())+"'";
stat.executeQuery(query);
ResultSet rs = stat.getResultSet();
while (rs.next()) {
int harga = rs.getInt("harga");
//String nama = rs.getString("nama");
System.out.println(harga);
}
} catch (SQLException e) {
e.printStackTrace();
}
}