Results 1 to 4 of 4
  1. #1
    WLX
    WLX is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default Getting from database, putting into jtextfield

    I have one entity class, a database package and the GUI.

    Now I have problem getting the info from the database to put into the jtextfield. The red selected words are the problem I faced.

    Entity:
    Java Code:
    package forms.ui.images.Entity;
    
    import java.sql.ResultSet;	
    import java.util.ArrayList;
    import forms.ui.images.database.DBController;
    
    public class Souv {
    public int itemLeft;
    
    public Souv() {	
    super();
    
    Souv(int itemLeft) {
    super();
    this.itemLeft = itemLeft;
    }
    
    public int getItemLeft() {
    return itemLeft;
    }
    public void setItemLeft(int itemLeft) {
    this.itemLeft = itemLeft;
    }
    
    
    public boolean retrieveSouvenirs(){		
    ResultSet rs = null;
    DBController db = new DBController();
    db.setUp("Database");
    String dbQuery = "SELECT * FROM Souvenirs WHERE ItemLeft =\'" + itemLeft + "\'"; 
    
    rs = db.readRequest(dbQuery);
    
    try{
    if (rs.next()){
    itemLeft = rs.getInt("ItemLeft");
    success = true;     
    }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    	
    db.terminate();
    return success;
    }

    GUI:

    Java Code:
    package forms.ui.images;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import forms.ui.images.Entity.Souv;
    
    public class Souvenirs extends JPanel {
    
    private JTextField jTextFieldLeft = null;
    private Souv Souvenir = null;
    
    public Souvenirs(MainFrame f) {
    super();
    myFrame = f; 
    initialize();
    }
    
    private void initialize() {
    this.add(jLabelLeft, null);
    }
    
    private JTextField getJTextFieldLeft() {
    if (jTextFieldLeft == null) {
    jTextFieldLeft = new JTextField();
    jTextFieldLeft.setBounds(new Rectangle(390, 210, 106, 31));
    jTextFieldLeft.setEditable(false);
    Souvenir.retrieveSouvenirs();
    jTextFieldLeft.setText([COLOR="Red"]Souvenir.getItemLeft().toString()[/COLOR]);
    }
    return jTextFieldLeft;
    }
    }
    Help me!!!

    :confused:

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    private Souv Souvenir = null;

    You never instanciated Souvenir. And read the coding conventions, variable names start with lower case letters.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    WLX
    WLX is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default

    Hello!

    I have changed to
    Java Code:
    private Souv Souvenir = new Souv();
    What do you mean by variable names start with lower case?

    Please guide me! Thanks!

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

Similar Threads

  1. Putting image into program
    By SprayAndPray69 in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 03:38 AM
  2. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  3. Putting code together.
    By newbee in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 03:53 AM
  4. Putting your own type in a Set
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:32 PM
  5. Putting controls in arrays?
    By Cymro in forum New To Java
    Replies: 4
    Last Post: 02-01-2008, 06:54 PM

Tags for this Thread

Posting Permissions

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