You don't need a
main
method in yourReports2
class. You main frame class already has amain
to launch from. Take out themain
method and wrap everything from thatmain
in aReport2
constructorYour
Reports2
class is already aJFrame
yet you are creating anotherJFrame
. Don't do that. instead justadd
to the classJFrame
JTable table = new JTable(buildTableModel(rs)); //JFrame frame = new JFrame("Reports"); <--- take this out //frame.setSize(800, 700); <--- don't set size, just pack setTitle("Reports"); <--- set title add(new JScrollPane(table)); <--- add to scrollpane pack(); <--- pack setVisible(true); <--- set visible
Notice how I took out the JFrame, since the class is already a
JFrame
As seen above, I use
.pack()
which is preferred rather than setting the sizeAnd lastly, all you need to do in the actionPerformed is instantiate the
Reports2
, that's itprivate void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { Report2 report = new Report2(); }
I ran it, and it works fine with the above mentioned fixes. Given your SQL is correct, it should run for you also.
Side Note: NEVER, EVER swallow your exceptions
} catch (Exception ex) {
}
Put something meaningful that will allow you to see what exceptions are being thrown if any.
} catch (Exception ex) {
ex.printStackTrace();
}
Also I would consider using a JDialog
(instead of a second JFrame
) as you can control its modality. It's just as easy to create a JDialog
as it is to create a JFrame
. It's almost the exact same process