java - How to save information from a combobox in the database -


i use combobox database information. want add product of respective category. category want selected combobox , recorded in database 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( don't know 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 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();  } 

enter image description here

this form apllication.

thank help, hope explain best possible

greetings

p1.setcategory( don't know code add);

you can bind items 1 one combobox result set.

while (rs1.next()) {  combobox.additem(rs1.getstring(1));//where 1 column index table retrived query } 

you can value this.

combobox.getselecteditem().tostring(); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -