Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: My code is not working :(

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry My code is not working :(

    Whats wrong with my code? the data from my database is not showing on my combo box..

    Im trying to get my data in my database to my combo box ..

    Here is my Code :



    private void Fillcombo(){
    Connection con = null;
    String url = "jdbc:mysql://localhost:3306/";
    String db = "purchasedb";
    String driver = "com.mysql.jdbc.Driver";
    String user = "root";
    String pass= "ajleal";

    try {


    con = DriverManager.getConnection(url+db,user,pass);
    Statement stmt= con.createStatement();
    ResultSet rs = stmt.executeQuery( "select * from supplier");

    while (rs.next()){
    String name = rs.getString("supn");
    jComboBox1.addItem("supn");
    }

    }catch(Exception e){

    JOptionPane.showMessageDialog(null,e);
    }

    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: My code is not working :(

    A lot of the time when people say "... doesn't show on my gui" it's a painting issue. Have you called repaint?
    Improving the world one idiot at a time!

  3. #3
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: My code is not working :(

    Most likely you're not on the EDT when adding those items. BTW: you're just adding "supn", you should probably add name. Did you make sure you actually enter the while loop?

Similar Threads

  1. Code not working
    By DPaul1994 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: May 10th, 2014, 01:41 PM
  2. Why is my Code not working?
    By Rhiannon1488 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 20th, 2014, 01:51 PM
  3. Replies: 1
    Last Post: March 18th, 2014, 02:56 AM
  4. Is my code working
    By return0 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 29th, 2013, 08:48 PM
  5. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM