i m trying to retrieve jtext fields and combo box values from another frame and to put them in database but .getText() doesn't return anything please help me thanx in advance
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try{ String sql = "select * from login where uid = ? and pass = ?"; pst = con.prepareStatement(sql); pst.setString(1, jTextField1.getText()); pst.setString(2, jTextField2.getText()); rs = pst.executeQuery(); if(rs.next()){ JOptionPane.showMessageDialog(null, "username and password is correct "); if(products.addProduct==true){ products p = new products(); p.addProduct(); products.addProduct=false; } }else{ JOptionPane.showMessageDialog(null, "username and password is not correct "); } }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } }
this is a password frame that calls addProduct() method from products class if password is correct.
Here is addProduct() method
public static void addProduct(){ try { int Productid = getProductTypeId(combo_Type.getSelectedItem().toString()); pst = con.prepareStatement("insert into product(pName,Product_type_id,pCost,pPrice,pQuantity,pModel,pCompany) values(?,?,?,?,?,?,?)"); pst.setString(1, txt_Product_name.getText()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.setInt(2, Productid); JOptionPane.showMessageDialog(null, "getProductTypeId is "+txt_Product_name.getText()); pst.setString(3, txt_Product_cost.getText()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.setString(4, txt_Product_price.getText()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.setString(5, txt_Product_Quatity.getText()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.setString(6, txt_Product_model.getText()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.setString(7, combo_brand.getSelectedItem().toString()); JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText()); pst.execute(); JOptionPane.showMessageDialog(null, "Saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { pst.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } Update_Table_Products(); }