-
why is it null?
I need to retrieve the f_topic and f_message from my database but it return a "null" when i run it.
However, there are already informtation stored inside my database.
How do i retrieve my f_topic and f_message without having the "null"?
Here's my code:
Code:
package HealthOK.ui;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.ImageIcon;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import HealthOK.entity.Forum;
import java.awt.Point;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ForumMessagePanel extends JPanel {
private static final long serialVersionUID = 1L;
private JLabel jLabelHeading = null;
private JLabel jLabelTopic = null;
private JTextField jTextFieldTopic = null;
private JLabel jLabelMessage = null;
private JTextField jTextFieldContent = null;
private JButton jButtonReply = null;
private JButton jButtonBack = null;
private JFrame myFrame = null;
private String f_topic, username, f_message;
private JScrollPane jScrollPaneReply = null;
private JTextArea jTextAreaReply = null;
private JButton jButtonPost = null;
/**
* This is the default constructor
*/
public ForumMessagePanel() {
super();
initialize();
}
public ForumMessagePanel(JFrame f){
this();
myFrame = f;
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabelMessage = new JLabel();
jLabelMessage.setBounds(new Rectangle(79, 150, 96, 27));
jLabelMessage.setFont(new Font("Dialog", Font.BOLD, 18));
jLabelMessage.setForeground(new Color(255, 51, 153));
jLabelMessage.setText("Message:");
jLabelTopic = new JLabel();
jLabelTopic.setBounds(new Rectangle(106, 107, 71, 29));
jLabelTopic.setFont(new Font("Dialog", Font.BOLD, 18));
jLabelTopic.setForeground(new Color(255, 51, 153));
jLabelTopic.setText("Topic:");
jLabelHeading = new JLabel();
jLabelHeading.setBounds(new Rectangle(122, 15, 428, 84));
jLabelHeading.setIcon(new ImageIcon(getClass().getResource("/HealthOK/ui/images/Forum.png")));
jLabelHeading.setText("");
this.setSize(700, 500);
this.setLayout(null);
this.setBackground(Color.white);
this.add(jLabelHeading, null);
this.add(jLabelTopic, null);
this.add(getJTextFieldTopic(), null);
this.add(jLabelMessage, null);
this.add(getJTextFieldContent(), null);
this.add(getJButtonReply(), null);
this.add(getJButtonBack(), null);
this.add(getJScrollPaneReply(), null);
this.add(getJButtonPost(), null);
Forum f1 = new Forum();
f1.retrieveForumQuestion();
jTextFieldTopic.setText(f1.getF_topic());
jTextFieldContent.setText(f1.getF_message());
System.out.println(" Topic is " + f1.getF_topic());
System.out.println(" Message is " + f1.getF_message());
}
/**
* This method initializes jTextFieldTopic
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldTopic() {
if (jTextFieldTopic == null) {
jTextFieldTopic = new JTextField();
jTextFieldTopic.setEnabled(true);
jTextFieldTopic.setLocation(new Point(183, 106));
jTextFieldTopic.setSize(new Dimension(350, 33));
jTextFieldTopic.setEditable(false);
}
return jTextFieldTopic;
}
/**
* This method initializes jTextFieldContent
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldContent() {
if (jTextFieldContent == null) {
jTextFieldContent = new JTextField();
jTextFieldContent.setBounds(new Rectangle(181, 149, 417, 110));
jTextFieldContent.setEditable(false);
}
return jTextFieldContent;
}
/**
* This method initializes jButtonReply
*
* @return javax.swing.JButton
*/
private JButton getJButtonReply() {
if (jButtonReply == null) {
jButtonReply = new JButton();
jButtonReply.setBounds(new Rectangle(82, 286, 111, 28));
jButtonReply.setFont(new Font("Dialog", Font.BOLD, 18));
jButtonReply.setText("Reply");
jButtonReply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jScrollPaneReply.setVisible(true);
jButtonPost.setVisible(true);
}
});
}
return jButtonReply;
}
/**
* This method initializes jButtonBack
*
* @return javax.swing.JButton
*/
private JButton getJButtonBack() {
if (jButtonBack == null) {
jButtonBack = new JButton();
jButtonBack.setBounds(new Rectangle(572, 21, 107, 40));
jButtonBack.setFont(new Font("Dialog", Font.BOLD, 18));
jButtonBack.setText("Back");
jButtonBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JPanel panel = new ForumPanel(myFrame);
removeAll();
add(panel);
validate();
repaint();
}
});
}
return jButtonBack;
}
/**
* This method initializes jScrollPaneReply
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPaneReply() {
if (jScrollPaneReply == null) {
jScrollPaneReply = new JScrollPane();
jScrollPaneReply.setLocation(new Point(185, 342));
jScrollPaneReply.setViewportView(getJTextAreaReply());
jScrollPaneReply.setSize(new Dimension(417, 110));
jScrollPaneReply.setVisible(false);
}
return jScrollPaneReply;
}
/**
* This method initializes jTextAreaReply
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextAreaReply() {
if (jTextAreaReply == null) {
jTextAreaReply = new JTextArea();
}
return jTextAreaReply;
}
/**
* This method initializes jButtonPost
*
* @return javax.swing.JButton
*/
private JButton getJButtonPost() {
if (jButtonPost == null) {
jButtonPost = new JButton();
jButtonPost.setBounds(new Rectangle(531, 458, 127, 36));
jButtonPost.setFont(new Font("Dialog", Font.BOLD, 14));
jButtonPost.setText("Submit Reply");
jButtonPost.setVisible(false);
}
return jButtonPost;
}
} // @jve:decl-index=0:visual-constraint="31,-7"
and here is what the console says:
DB Query: SELECT * FROM ForumQuestion WHERE f_topic ='null' and f_message = 'null'
Connection is closed
Topic is null
Message is null
-
Re: why is it null?
Don't double post the identically same question. The thread you started about 5 hours after this one has been deleted.
Repeated double posting may lead to a temporary or permanent ban.
db
-
Re: why is it null?
Am I being blind?
I can't see any database stuff in there at all?