try{   
    String str = "select * from stocks";
    stmt = conn.prepareStatement(str);
    ResultSet rs = stmt.executeQuery();

    while(rs.next())     
        jcbStock.addItem(rs.getString("stockID"));        
                }catch(Exception e){
                e.printStackTrace();           
        }

I have this code in other class , and i want call it in my main class. Anyone can tell me how to do?

Put that code in a public method and call that method from your main class

    public combobox(){ 
        JComboBox jcb = new JComboBox();
        try{   
    String str = "select * from stocks";
    stmt = conn.prepareStatement(str);
    ResultSet rs = stmt.executeQuery();

    while(rs.next())     
        jcb.addItem(rs.getString("stockID"));        
                }catch(Exception e){
                e.printStackTrace();           
                }
    }

Is it look like this?

Anyone can help me, i have no idea how to get it ?

why would you return the combobox? how about just the value ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.