Datainsert through SubQuery.


 try
    {
   int id1=Integer.parseInt(jTextField23.getText());
  
   int amount=Integer.parseInt(jTextField25.getText());
   String mop=(String)jComboBox4.getSelectedItem();
    String rp=(String)jComboBox5.getSelectedItem();
 
        Connection c=new Connection();
            java.sql.Connection con=c.connectit();
        Statement stmt=con.createStatement();
        String s="select * from returngoods where id='"+id1+"'";
        ResultSet rs=stmt.executeQuery(s);
        if(rs.next())
        {
            JOptionPane.showMessageDialog(null,"Already Returned!!!");
        }
        else
        {
        String sql="insert into returngoods values('"+id1+"',(select BrandName from stock where id='"+id1+"')"
                + ",(select VendorName from stock where id='"+id1+"')"
                + ",(select Description from stock where id='"+id1+"')"
                + ",(select Quantity from stock where id='"+id1+"')"
                + ",(select Category from stock where id='"+id1+"')"
                + ",(select Size from stock where id='"+id1+"')"
                + ",(select Color from stock where id='"+id1+"')"
                + ",(select PurchaseDate from stock where id='"+id1+"')"
                + ",(select SellingPrice from stock where id='"+id1+"')"
                + ",(select PurchaseCost from stock where id='"+id1+"')"
                + ",(select Product from stock where id='"+id1+"')"
                + ",(select Discount from stock where id='"+id1+"')"
                + ",'"+mop+"','"+rp+"',"+amount+")";
          
      
           int i= stmt.executeUpdate(sql);
            if(i>0)
            {
               JOptionPane.showMessageDialog(null,"Saved!");
            }
            else
            {
                JOptionPane.showMessageDialog(null,"Unsaved!!");
            }
            String sql2="delete from stock where id='"+id1+"'";
            stmt.executeUpdate(sql2);
    }
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null,e);
        System.out.println(e);
    }
    table3();
    table();
    set();
}

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.