I am trying to print out on the label but i cannot print anything even after connecting to the database successfully. The pop up shows but no data is shown. When i remove the rs.next() and replace it with any string the message shows but when i use the rs.next(), the message becomes empty.
String query = "SELECT * FROM OZEKIMESSAGEIN WHERE ID=1";
Statement st = connection.prepareStatement(query);
ResultSet rs = st.executeQuery(query);
JFrame frame = new JFrame();
frame.setSize(300,125);
frame.setUndecorated(true);
frame.setLayout(new GridBagLayout());
JLabel headingLabel = new JLabel();
while(rs.next()){
String value = rs.getString("msg");
headingLabel.setText("The mpesa message is" + value);
}
Icon headingIcon = null;
headingLabel .setIcon(headingIcon); // --- use image icon you want to be as heading image.
headingLabel.setOpaque(false);
JLabel messageLabel = new JLabel();
while(rs.next()){
messageLabel.setText(rs.getString("MSG"));
}
frame.add(messageLabel, constraints);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
java.awt.Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
new Thread(){
@Override
public void run() {
try {
Thread.sleep(10000); // time after which pop up will disappear.
frame.dispose();
} catch (InterruptedException e) {
}
};
}.start();