Add Product Through yes no option


int p=JOptionPane.showConfirmDialog(null,"Do U Want to Add","Add Product",JOptionPane.YES_NO_OPTION);
      if(p==0)
      {
        try
       {
           Class.forName("com.mysql.jdbc.Driver");
           java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
           java.sql.PreparedStatement pst1=con.prepareStatement("select * from inventory where Product_Code='"+jTextField2.getText()+"'");
           ResultSet rs=pst1.executeQuery();
           if(rs.next())
           {
              JOptionPane.showMessageDialog(null,"Already Exists!!");
              con.close();
              pst1.close();
              rs.close();
           }
           else
           {
               java.sql.Date sqldate = new java.sql.Date(jd1.getDate().getTime());
               String sql="insert into inventory(Product_Code,Product_Name,Quantity,Cost_Price,Selling_Price,Total_Price,Brand_Name,Descrption,Date,Vendor_Name) values(?,?,?,?,?,?,?,?,?,?)";
              java.sql.PreparedStatement pst=con.prepareStatement(sql);
               pst.setString(1,jTextField2.getText());
               pst.setString(2,jTextField1.getText());
               pst.setInt(3,Integer.parseInt(jTextField3.getText()));
               pst.setDouble(4,Double.parseDouble(jTextField4.getText()));
               pst.setDouble(5,Double.parseDouble(jTextField5.getText()));
               pst.setDouble(6,Double.parseDouble(jTextField7.getText()));
               pst.setString(7,jComboBox2.getSelectedItem().toString());
               pst.setString(8,jTextArea1.getText());
               pst.setDate(9,sqldate);
               pst.setString(10,jTextField8.getText());
               pst.executeUpdate();
               reset();
               pst.close();
               con.close();
           }
       }
       catch(Exception e)
       {
           System.out.println(e);
       }
}

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.