I have another class where a user a Book a resort, by only typing in the ID of the resort. Then a new JFrame opens(ConfirmBooking) where it displays the Name of the Resort and Price per night on labels. But I seem to be getting an error where I try to load the Resort name and price from the SQL database.
Error I get: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
public class ConfirmBooking extends javax.swing.JFrame
{
Connection conn = null;
Statement stat = null;
ResultSet res = null;
Booking B = new Booking();
public ConfirmBooking()
{
initComponents();
String sql = "SELECT RESORT_NAME, COST_PER_NIGHT_ZAR FROM LouwDataBase.Resorts WHERE ID = "+ 2;
try (PreparedStatement pstmt = conn.prepareStatement(sql))
{
try (ResultSet rs = pstmt.executeQuery())
{
if (rs.next())
{
String Name = rs.getString("RESORT_NAME");
double Price = rs.getDouble("COST_PER_NIGHT_ZAR");
String Rands = Double.toString(Price);
ResortName.setText(Name);
ResortPrice.setText("R"+Rands);
}
}
}
catch (SQLException ex)
{
Logger.getLogger(Booking.class.getName()).log(Level.SEVERE, null, ex);
}
}