Insrt data through jquery.
package Connect;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class selling
{
public int ID;
public String Bill_No;
public String Bill_Date;
public String Order_No;
public String Customer_Name;
public String Buyer_Tin;
public String Order_Date;
public String Product_Code;
public String Bill_Type;
public String Product_Name;
public double Sell_Price;
public int Sale_Quantity;
public double Total;
public double VAT;
public double SAT;
public double Round_Off;
public double Grand_Total;
public double SaleByAmount;
public double Margin;
public int getID() {
return ID;
}
public String getBill_No() {
return Bill_No;
}
public void setBill_No(String Bill_No) {
this.Bill_No = Bill_No;
}
public String getBill_Date() {
return Bill_Date;
}
public void setBill_Date(String Bill_Date) {
this.Bill_Date = Bill_Date;
}
public String getOrder_No() {
return Order_No;
}
public void setOrder_No(String Order_No) {
this.Order_No = Order_No;
}
public String getCustomer_Name() {
return Customer_Name;
}
public void setCustomer_Name(String Customer_Name) {
this.Customer_Name = Customer_Name;
}
public String getBuyer_Tin() {
return Buyer_Tin;
}
public void setBuyer_Tin(String Buyer_Tin) {
this.Buyer_Tin = Buyer_Tin;
}
public String getOrder_Date() {
return Order_Date;
}
public void setOrder_Date(String Order_Date) {
this.Order_Date = Order_Date;
}
public String getProduct_Code() {
return Product_Code;
}
public void setProduct_Code(String Product_Code) {
this.Product_Code = Product_Code;
}
public String getBill_Type() {
return Bill_Type;
}
public void setBill_Type(String Bill_Type) {
this.Bill_Type = Bill_Type;
}
public String getProduct_Name() {
return Product_Name;
}
public void setProduct_Name(String Product_Name) {
this.Product_Name = Product_Name;
}
public double getSell_Price() {
return Sell_Price;
}
public void setSell_Price(double Sell_Price) {
this.Sell_Price = Sell_Price;
}
public int getSale_Quantity() {
return Sale_Quantity;
}
public void setSale_Quantity(int Sale_Quantity) {
this.Sale_Quantity = Sale_Quantity;
}
public double getTotal() {
return Total;
}
public void setTotal(double Total) {
this.Total = Total;
}
public double getVAT() {
return VAT;
}
public void setVAT(double VAT) {
this.VAT = VAT;
}
public double getSAT() {
return SAT;
}
public void setSAT(double SAT) {
this.SAT = SAT;
}
public double getRound_Off() {
return Round_Off;
}
public void setRound_Off(double Round_Off) {
this.Round_Off = Round_Off;
}
public double getGrand_Total() {
return Grand_Total;
}
public void setGrand_Total(double Grand_Total) {
this.Grand_Total = Grand_Total;
}
public double getSaleByAmount() {
return SaleByAmount;
}
public void setSaleByAmount(double SaleByAmount) {
this.SaleByAmount = SaleByAmount;
}
public double getMargin() {
return Margin;
}
public void setMargin(double Margin) {
this.Margin = Margin;
}
public selling(int ID, String Bill_No, String Bill_Date, String Order_No, String Customer_Name, String Buyer_Tin, String Order_Date, String Product_Code, String Bill_Type, String Product_Name, double Sell_Price, int Sale_Quantity, double Total, double VAT, double SAT, double Round_Off, double Grand_Total, double SaleByAmount, double Margin) {
this.ID = ID;
this.Bill_No = Bill_No;
this.Bill_Date = Bill_Date;
this.Order_No = Order_No;
this.Customer_Name = Customer_Name;
this.Buyer_Tin = Buyer_Tin;
this.Order_Date = Order_Date;
this.Product_Code = Product_Code;
this.Bill_Type = Bill_Type;
this.Product_Name = Product_Name;
this.Sell_Price = Sell_Price;
this.Sale_Quantity = Sale_Quantity;
this.Total = Total;
this.VAT = VAT;
this.SAT = SAT;
this.Round_Off = Round_Off;
this.Grand_Total = Grand_Total;
this.SaleByAmount = SaleByAmount;
this.Margin = Margin;
}
public selling(String Customer_Name, String Product_Name, int Sale_Quantity) {
this.Customer_Name = Customer_Name;
this.Product_Name = Product_Name;
this.Sale_Quantity = Sale_Quantity;
}
public selling() {
}
public ArrayList list()
{
ArrayList ar=new ArrayList();
try
{
databse d=new databse();
Connection con=d.connectit();
String sql="select Customer_Name,Product_Name,Sale_Quantity from sales";
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
String name=rs.getString(1);
String p=rs.getString(2);
int q=rs.getInt(3);
ar.add(new selling(name,p,q));
}
pst.close();
con.close();
rs.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return ar;
}
public ArrayList list1(String d1,String d2)
{
ArrayList ar=new ArrayList();
try
{
databse d=new databse();
Connection con=d.connectit();
String sql="SELECT sum(Total),sum(Sale_Quantity) from sales where Bill_Date between '"+d1+"' and '"+d2+"'";
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
double total=rs.getDouble(1);
int sq=rs.getInt(2);
ar.add(new selling(total,sq));
}
pst.close();
con.close();
rs.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return ar;
}
public ArrayList list2(String d1,String d2)
{
ArrayList ar=new ArrayList();
try
{
databse d=new databse();
Connection con=d.connectit();
String sql="SELECT Product_Code,Product_Name,Sale_Quantity as Qty_Sold,Sell_Price,Margin,SaleByAmount from sales where Bill_Date between '"+d1+"' and '"+d2+"'";
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
String code=rs.getString(1);
String name=rs.getString(2);
int sq=rs.getInt(3);
double Sell_Price=rs.getDouble(4);
double margin=rs.getDouble(5);
double sa=rs.getDouble(6);
ar.add(new selling(code,name,sq,Sell_Price,margin,sa));
}
pst.close();
con.close();
rs.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return ar;
}
public selling(String Product_Code, String Product_Name,int Sale_Quantity, double Sell_Price, double SaleByAmount, double Margin) {
this.Product_Code = Product_Code;
this.Product_Name = Product_Name;
this.Sell_Price = Sell_Price;
this.Sale_Quantity = Sale_Quantity;
this.SaleByAmount = SaleByAmount;
this.Margin = Margin;
}
public selling( double Total,int Sale_Quantity) {
this.Sale_Quantity = Sale_Quantity;
this.Total = Total;
}
public int coun()
{
int c=0;
try
{
databse d=new databse();
Connection con=d.connectit();
String sql= "SELECT count(*) from sales";
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
c=rs.getInt(1);
}
}
catch(Exception e)
{
System.out.println(e);
}
return c;
}
public void insert()
{
try
{
databse d=new databse();
Connection con=d.connectit();
String sql= "insert into sales1(ID,Bill_No,Bill_Date,Order_No,Customer_Name,Buyer_Tin,Order_Date,Product_Code,Bill_Type,Product_Name,Sell_Price, Sale_Quantity,Total,VAT,SAT,Round_Off,Grand_Total,SaleByAmount,Margin) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pst=con.prepareStatement(sql);
pst.setInt(1,(coun()+1));
pst.setString(2,Bill_No);
pst.setString(3,Bill_Date);
pst.setString(4,Order_No);
pst.setString(5,Customer_Name);
pst.setString(6,Buyer_Tin);
pst.setString(7,Order_Date);
pst.setString(8,Product_Code);
pst.setString(9, Bill_Type);
pst.setString(10, Product_Name);
pst.setDouble(11, Sell_Price);
pst.setInt(12,Sale_Quantity);
pst.setDouble(13,Total);
pst.setDouble(14, VAT);
pst.setDouble(15, SAT);
pst.setDouble(16, Round_Off);
pst.setDouble(17, Grand_Total);
pst.setDouble(18, SaleByAmount);
pst.setDouble(19,Margin);
System.out.println("naveen");
pst.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
}
public selling(String Bill_No, String Bill_Date, String Order_No, String Customer_Name, String Buyer_Tin, String Order_Date, String Product_Code, String Bill_Type, String Product_Name, double Sell_Price, int Sale_Quantity, double Total, double VAT, double SAT, double Round_Off, double Grand_Total, double SaleByAmount, double Margin) {
this.Bill_No = Bill_No;
this.Bill_Date = Bill_Date;
this.Order_No = Order_No;
this.Customer_Name = Customer_Name;
this.Buyer_Tin = Buyer_Tin;
this.Order_Date = Order_Date;
this.Product_Code = Product_Code;
this.Bill_Type = Bill_Type;
this.Product_Name = Product_Name;
this.Sell_Price = Sell_Price;
this.Sale_Quantity = Sale_Quantity;
this.Total = Total;
this.VAT = VAT;
this.SAT = SAT;
this.Round_Off = Round_Off;
this.Grand_Total = Grand_Total;
this.SaleByAmount = SaleByAmount;
this.Margin = Margin;
}
}
$(document).ready(function(){
$("#add").click(function(){
$.ajax({
type: "post",
url: "subquantity.jsp",
data: {
input: $('#pc').val(),
output: $('#sq').val(),
bill:$('#bill').val(),
billdate:$('#billdate').val(),
on:$('#on').val(),
cn:$('#cn').val(),
bt:$('#bt').val(),
od:$('#od').val(),
bit:$('#combo').val(),
pn:$('#pn').val(),
mrp:$('#mrp').val(),
sq:$('#sq').val(),
total:$('#total').val(),
sat:$('#sat').val(),
satsat:$('#satsat').val(),
vat:$('#vat').val(),
vatvat:$('#vatvat').val(),
gd:$('#gd').val()
},
success: function(msg)
{
$('#output').append(msg);
}
});
});
<table>
<tr>
<td>Bill Number</td>
<td><input type="text" name="bill" class="text4" id="bill"></td>
<td>Bill Date</td>
<td><input type="text" name="billdate" class="text4" id="billdate"></td>
<td>Order Number</td>
<td><input type="text" name="on" class="text4" id="on"></td>
</tr>
<tr>
<td>Customer Name</td>
<td><input type="text" name="cn" class="text4" id="cn"></td>
<td>Buyer Tin</td>
<td><input type="text" name="bt" class="text4" id="bt"></td>
<td>Order Date</td>
<td><input type="text" name="od" class="text4" id="od"></td>
</tr>
<tr>
<td>Product Code</td>
<td><input type="text" name="pc" class="text4" id="pc"></td>
<td>Bill Type</td>
<td><select onchange="dis()" id="combo" name="bit">
<option value="Sales Invoice" class="text5">Sales Invoice</option>
<option value="Tax Invoice" class="text5">Tax Invoice</option>
</select></td>
<td>Product Name</td>
<td><input type="text" name="pn" class="text4" id="pn"></td>
</tr>
<tr>
<td>Avaliable Quantity</td>
<td><input type="text" name="aq" class="text4" id="aq"></td>
<td>M_R_P</td>
<td><input type="text" name="mrp" class="text4" id="mrp"></td>
<td>Sale Quantity</td>
<td><input type="text" name="sq" class="text4" id="sq" onkeyup="bb()"></td>
</tr>
<tr>
<td>Total</td>
<td><input type="text" name="total" class="text4" id="total"></td>
<td>Vat</td>
<td><input type="text" name="vat" class="text6" id="vat" onkeypress="cc()"></td>
<td>Vat Value</td>
<td><input type="text" name="vatvat" class="text4" id="vatvat"></td>
</tr>
<tr>
<td>Sat</td>
<td><input type="text" name="sat" class="text6" id="sat" onkeypress="dd()"></td>
<td>Sat Value</td>
<td><input type="text" name="satsat" class="text4" id="satsat"></td>
<td>Grand Total</td>
<td><input type="text" name="gd" class="text4" id="gd"></td>
</tr>
</table>
</div>
<div class="buttons">
<button class="button1" onclick="return myFunction()" id="add">Add To Cart</button>
<input type="submit" class="button1" value="Print"/>
<input type="button" onclick="return reset1()" value="Reset Form" class="button1"/>
<input type="button" value="Delete" class="button1" id="delete">
<div id="output"></div>
</div>
</form>
<div class="addtocart">
</div>
<div class="left1">
<table id="addtocart" border="1" style="border-radius: 2px;">
<th>Product_Name</th><th>Product_Code</th><th>Quantity</th><th>Unit_Rupees</th><th>Amount</th>
</table>
</div>
subquantity.jsp
<%--
Document : subquantity
Created on : Aug 6, 2014, 2:24:05 PM
Author : NAVJYOTI
--%>
<%@page import="Connect.Invent"%>
<%@page import="java.sql.Connection"%>
<%@page import="Connect.databse"%>
<%@page import="Connect.*"%>
<jsp:useBean id="i" class="Connect.Invent"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String iii=request.getParameter("input");
int q=Integer.parseInt(request.getParameter("output"));
System.out.println(q);
Invent ii=new Invent(iii,q);
ii.updatequantity();
String bina=request.getParameter("bill");
System.out.println("Bill"+bina);
String bidat=request.getParameter("billdate");
System.out.println("Billdate"+bidat);
String on=request.getParameter("on");
System.out.println("on"+on);
String cn=request.getParameter("cn");
System.out.println("cn"+cn);
String bt=request.getParameter("bt");
System.out.println("bt"+bt);
String od=request.getParameter("od");
System.out.println("od"+od);
String bit=request.getParameter("bit");
System.out.println("bit"+bit);
String pn=request.getParameter("pn");
System.out.println("pn"+pn);
double mrp=Double.parseDouble(request.getParameter("mrp"));
System.out.println("mrp"+mrp);
int sq=Integer.parseInt(request.getParameter("sq"));
System.out.println("sq"+sq);
double total=Double.parseDouble(request.getParameter("total"));
System.out.println("total"+total);
double vat=Double.parseDouble(request.getParameter("vat"));
System.out.println("vat"+vat);
double vatvat=Double.parseDouble(request.getParameter("vatvat"));
System.out.println("vatvat"+vatvat);
double sat=Double.parseDouble(request.getParameter("sat"));
System.out.println("sat"+sat);
double satsat=Double.parseDouble(request.getParameter("satsat"));
System.out.println("satsat"+satsat);
double gd=Double.parseDouble(request.getParameter("gd"));
System.out.println("gd"+gd);
selling s=new selling(bina,bidat,on,cn,bt,od,iii,bit,pn,mrp,sq,0,0,0,0,0,0,0);
System.out.println("naveen");
s.insert();
%>
</body>
</html>