Results 1 to 3 of 3

Thread: why is it null?

  1. #1
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default 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:
    Java 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: why is it null?

    Am I being blind?
    I can't see any database stuff in there at all?

Similar Threads

  1. Why I'm getting NULL
    By amrmb09 in forum Advanced Java
    Replies: 23
    Last Post: 11-09-2011, 12:54 AM
  2. Replies: 6
    Last Post: 10-18-2010, 10:40 AM
  3. Null :(
    By PhQ in forum Advanced Java
    Replies: 4
    Last Post: 04-12-2010, 01:05 AM
  4. Replies: 2
    Last Post: 03-19-2010, 05:30 PM
  5. Null
    By leapinlizard in forum New To Java
    Replies: 4
    Last Post: 04-29-2009, 11:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •