adding items in jcombobox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Norgy
    New Member
    • May 2013
    • 56

    adding items in jcombobox

    Code:
        private void pnosActionPerformed(java.awt.event.ActionEvent evt) {
      
           try { 
                 Class.forName("com.mysql.jdbc.Driver");
                try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/depatment", "root","riham00879")) {
                    Statement statement = connection.createStatement();
                    String query = "SELECT * FROM protocol";
                    ResultSet rs = statement.executeQuery(query);
    
                    while (rs.next())
                    {      
                       String pno = rs.getString("pno");         
                      pnos.addItem("pno");
                          System.out.println(pno);
                    }
                }
                 } catch (ClassNotFoundException | SQLException e) {
                 }
           
        }
    i am trying to get data from MySQL database and print it in the jcombobox but nothing is printed
    what is the problem ??
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    I'm no expert in the MySQL stuff but I see you're using System.out.prin tln(pno); is this how you're trying to set the contents of the jcombobox? Because that won't work; that will only print the value of pno to the standard output, which is probably a console. What you want to use is JComboBox.addIt em(...) to add something to the JComboBox.

    Comment

    • Norgy
      New Member
      • May 2013
      • 56

      #3
      i tried to write -> pnos.addItem(pn o);
      and removed the line of System.out.prin tln
      but the problem hasn't resolved yet

      Comment

      Working...