Reputation: 103
So basically the values from database are fetched and displayed in JTable. I wanted a popup to appear if one of the fields contain a value. For example , I want that if the section_name in JTable is "Executive Summary" then a popup should appear. But what I find is that the if condition in line 12 gets executed even if the section_name is not "Executive Summary".This is the if block that I am referring to:-
if (section_name.equals("Executive Summary"));
{
JOptionPane.showMessageDialog(null, "it works", "Error", JOptionPane.ERROR_MESSAGE);
}
The popup displays each time. Where lies the error and how should it be corrected.
ResultSet rs = pst.executeQuery();
int i = 0;
while (rs.next()) {
section_name = rs.getString("Section_Name");
report_name = rs.getString("Report_Name");
contact_name = rs.getString("Contact_Name");
link = rs.getString("Link");
String m="apple";
model.addRow(new Object[]{section_name, report_name, contact_name, link,m});
i++;
}
if (section_name.equals("Executive Summary"));
{
JOptionPane.showMessageDialog(null, "it works", "Error", JOptionPane.ERROR_MESSAGE);
}
if (i < 1)
{
JOptionPane.showMessageDialog(null, "No Record Found", "Error", JOptionPane.ERROR_MESSAGE);
}
if (i == 1)
{
System.out.println(i + " Record Found");
} else {
System.out.println(i + " Records Found");
}
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
Upvotes: 0
Views: 73
Reputation: 6437
You need to remove the semi-colon at the end of this line:
if (section_name.equals("Executive Summary"));
Make it:
if (section_name.equals("Executive Summary"))
{
....
}
By leaving the semi-colon in, it make's it the equivalent of:
if (section_name.equals("Executive Summary")) {}
{
.... /* always executed */
}
Upvotes: 6