Results 1 to 4 of 4
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default No values from database in Combobox

    Hello Guys,

    For you all a happy, healthy and blessed 2011.

    I have a tabel students and i want to display the primary key "code" in my JComboBox.

    So i developed some code in my class and in the form. I excpect to see values but unfortunatly there isn't.

    Getters
    Java Code:
     public int getAllCode(){
        return allCode;
      }
    
       public int getFirstCode(){
        return firstCode;
      }
    Setters

    Java Code:
    public void setAllCode(int allCode) {
        this.allCode = allCode;
      }
    
    public void setFirstCode(int firstCode) {
        this.firstCode = code;
      }
    query code for selected item (first record "code")

    Java Code:
    public static Student getFirstStudent(int code) {
    
        Student value = new Student();
    
        String query = "SELECT code FROM student LIMIT 1";
        ResultSet r = Database.executeSelectQuery(query);
    
         try {
            r.next();
    
            value.firstCode = r.getInt("firstCode");
            value.setAchternaam(r.getString("achternaam"));
            System.out.println("Student: getStudenten: betaald " + r.getInt("betaald"));
            value.setBetaald(r.getInt("betaald"));
    
    
            }
         catch (SQLException e) {
          System.out.println("Student: getStudent: " + e.toString());
          System.out.println(e.getMessage() + "\n" + e.getSQLState() + "\n" + e.getErrorCode());
        }
        return value;
      }
    Query code for the whole list

    Java Code:
    public static Student getAllStudent(int allCode) {
    
        Student value = new Student();
    
        String query = "select code from student";
        ResultSet r = Database.executeSelectQuery(query);
    
         try {
            r.next();
    
            value.allCode = r.getInt("allCode");
            value.setAchternaam(r.getString("achternaam"));
            System.out.println("Student: getStudenten: betaald " + r.getInt("betaald"));
            value.setBetaald(r.getInt("betaald"));
    
    
            }
         catch (SQLException e) {
          System.out.println("Student: getStudent: " + e.toString());
          System.out.println(e.getMessage() + "\n" + e.getSQLState() + "\n" + e.getErrorCode());
        }
        return value;
      }

    View (Gui) code for the JComboBox


    Java Code:
      codeComboBox.setSelectedItem( aStudent.getFirstCode());
      codeComboBox.addItem( aStudent.getAllCode());
    The first time i used a combobox, so please help.

    Kind regards,

    André

  2. #2
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I forget the code for getting it al to a string:
    Java Code:
     public String toString() {
        
        String output = "";
        output += getCode() + "  " + getAchternaam() + "  " ;
        output += getAllCode() + "  " + getAchternaam() + "  " ;
        output += getFirstCode();
        output += getGeboortedatum() + "  " + getOpleiding() + "  ";
        output += slber.getAchternaam();
        return output;
      }
    I think i'm on the right way but i'm missing something.

  3. #3
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    The problem :-(
    Attached Thumbnails Attached Thumbnails No values from database in Combobox-problem.jpg  

  4. #4
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

Similar Threads

  1. inserting values from jtable into database
    By sandeepsai17 in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 08:31 PM
  2. List in Combobox database values
    By Glouze in forum Advanced Java
    Replies: 1
    Last Post: 01-16-2009, 06:26 PM
  3. How to store extracted xml values in a database?
    By palanikumark in forum Advanced Java
    Replies: 6
    Last Post: 05-30-2008, 01:14 PM
  4. getting values from database in dropdown
    By aa74 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-21-2008, 11:00 PM
  5. ComboBox with database options
    By Goldy in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2007, 10:43 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
  •