How to save information from a combobox in the database

I use combobox with database information. I want to add a product of the respective category. This category want it to be selected by a combobox and it is recorded in the database from there.

  public void addProducts() {
      try {
        Products p1 = new Products();
        p1.setIdProduct(jTIdProduct.getText());
        p1.setDescProduct(jTDescProduct.getText());
        p1.setStockActual(jTStockA.getText());
        p1.setStockMin(jTStockM.getText());
        p1.setPrice(jTPrice.getText());
        p1.setNumOrc(jTNOrc.getText());

    -------->     p1.setcategory( THIS IS WHERE i DON'T KNOW WHAT CODE ADD);


        ProductDao dao = new ProductDao();
        dao.addProduct(p1);

    } catch (SQLException ex) {
        Logger.getLogger(jTProduct.class.getName()).log(Level.SEVERE, null, ex);
    }
}

----------------------CLASS DAO-------------------------------------------

  public void addProducts(Products p1) throws SQLException {
    String sql = "insert into Products (idProduct, descProduct, stockActual, stockMin, price, numOrc, category)" + "values (?,?,?,?,?,?,?)";



    PreparedStatement stmt = conexao.prepareStatement(sql);
    stmt.setString(1, p1.idProduct());
    stmt.setString(2, p1.getDescProduct());
    stmt.setString(3, p1.getStockActual());
    stmt.setString(4, p1.getStockMin());
    stmt.setString(5, p1.getPrice());
    stmt.setString(6, p1.getNumOrc());
    stmt.setString(7, p1.getCategory());

    stmt.execute();
    stmt.close();
    conexao.close();

}

This is form from my apllication.

Thank you all for the help, I hope to explain as best as possible

Greetings

Answers


p1.setcategory( THIS IS WHERE i DON'T KNOW WHAT CODE ADD);

You can bind items one by one to combobox from result set.

while (rs1.next()) {
 comboBox.addItem(rs1.getString(1));//where 1 is column index for table retrived by query
}

You can get Value like this.

comboBox.getSelectedItem().toString();

Need Your Help

How do I browse a different git branch without checking it out

git merge branch branching-and-merging git-merge

I've just merged two branches in git. Now I'm examining my (broken) code in Eclipse (on Windows). I'd like to be able to browse the HEAD of the source branch without checking it out. I know I can u...

match names in csv file to filename in folder

python

I have got a list of about 7000 names in a csv file that is arranged by surname, name, date of birth etc. I also have a folder of about 7000+ scanned documents (enrolment forms) which have the nam...