Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added JDBC Assignment.zip
Binary file not shown.
44 changes: 44 additions & 0 deletions SQL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE table TBL_STOCK
(Product_ID VARCHAR2(6) PRIMARY KEY,
Product_Name VARCHAR2(20) UNIQUE,
Quantity_On_Hand NUMBER,
Product_Unit_Price NUMBER,
Reorder_Level NUMBER,
constraint TBL_STOCK_C1 check (Quantity_On_Hand >=0),
constraint TBL_STOCK_C2 check (Product_Unit_Price >=0),
constraint TBL_STOCK_C3 check (Reorder_Level >=0),
)

CREATE table TBL_SALES (
Sales_ID VARCHAR2(6) PRIMARY KEY,
Sales_Date DATE,
Product_ID VARCHAR2(6),
Quantity_Sold NUMBER,
Sales_Price_Per_Unit NUMBER,
constraint TBL_SALES_C1 check (Quantity_Sold >=0),
constraint TBL_SALES_C2 check (Sales_Price_Per_Unit >=0),
constraint TBL_SALES_C3 FOREIGN KEY (Product_ID) REFERENCES TBL_STOCK(Product_ID)
)

insert into TBL_STOCK values('RE1001','REDMI Note 3',20,12000,5)

insert into TBL_STOCK values('ip1002','Iphone 5S',10,21000,2)

insert into TBL_STOCK values('PA1003','Panasonic P55',50,5500,5)

create sequence SEQ_SALES_ID start with 1000 increment by 1 nocache nocycle noorder

create sequence SEQ_PRODUCT_ID start with 1004 increment by 1 nocache nocycle noorder

create view V_SALES_REPORT as
select
Sales_ID, Sales_Date, Product_ID, Product_Name, Quantity_Sold, Product_Unit_Price, Sales_Price_Per_Unit,
(Sales_Price_Per_Unit - Product_Unit_Price) Profit_Amount
from TBL_STOCK natural join TBL_SALES
order by Profit_Amount desc, Sales_ID asc

drop table TBL_STOCK
drop table TBL_SALES
drop sequence SEQ_SALES_ID
drop sequence SEQ_PRODUCT_ID
drop view V_SALES_REPORT
1 change: 1 addition & 0 deletions Sales.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -jar Sales.jar
Binary file added Sales.jar
Binary file not shown.
Binary file added wipro/bin/bean/Sales.class
Binary file not shown.
Binary file added wipro/bin/bean/SalesReport.class
Binary file not shown.
Binary file added wipro/bin/bean/Stock.class
Binary file not shown.
Binary file added wipro/bin/dao/SalesDao.class
Binary file not shown.
Binary file added wipro/bin/dao/StockDao.class
Binary file not shown.
Binary file added wipro/bin/main/SalesApplication.class
Binary file not shown.
Binary file added wipro/bin/module-info.class
Binary file not shown.
Binary file added wipro/bin/services/Administrator.class
Binary file not shown.
Binary file added wipro/bin/util/DBUtil.class
Binary file not shown.
42 changes: 42 additions & 0 deletions wipro/sales/bean/Sales.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package bean;

import bean.*;
import java.util.Date;
public class Sales {
String salesID;
Date salesDate;
String productID;
int quantitySold;
double salesPricePerUnit;

public String getSalesID() {
return salesID;
}
public void setSalesID(String salesID) {
this.salesID = salesID;
}
public Date getSalesDate() {
return salesDate;
}
public void setSalesDate(Date salesDate) {
this.salesDate = salesDate;
}
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public int getQuantitySold() {
return quantitySold;
}
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}
public double getSalesPricePerUnit() {
return salesPricePerUnit;
}
public void setSalesPricePerUnit(double salesPricePerUnit) {
this.salesPricePerUnit = salesPricePerUnit;
}
}
64 changes: 64 additions & 0 deletions wipro/sales/bean/SalesReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package bean;

import java.util.Date;

public class SalesReport {
String salesID;
Date salesDate;
String productID;
String productName;
int quantitySold;
double productUnitPrice;
double salesPricePerUnit;
double profitAmount;

public String getSalesID() {
return salesID;
}
public void setSalesID(String salesID) {
this.salesID = salesID;
}
public Date getSalesDate() {
return salesDate;
}
public void setSalesDate(Date salesDate) {
this.salesDate = salesDate;
}
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getQuantitySold() {
return quantitySold;
}
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}
public double getProductUnitPrice() {
return productUnitPrice;
}
public void setProductUnitPrice(double productUnitPrice) {
this.productUnitPrice = productUnitPrice;
}
public double getSalesPricePerUnit() {
return salesPricePerUnit;
}
public void setSalesPricePerUnit(double salesPricePerUnit) {
this.salesPricePerUnit = salesPricePerUnit;
}
public double getProfitAmount() {
return profitAmount;
}
public void setProfitAmount(double profitAmount) {
this.profitAmount = profitAmount;
}

}
41 changes: 41 additions & 0 deletions wipro/sales/bean/Stock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package bean;

public class Stock {
String productID;
String productName;
int quantityOnHand;
double productUnitPrice;
int reorderLevel;

public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getQuantityOnHand() {
return quantityOnHand;
}
public void setQuantityOnHand(int quantityOnHand) {
this.quantityOnHand = quantityOnHand;
}
public double getProductUnitPrice() {
return productUnitPrice;
}
public void setProductUnitPrice(double productUnitPrice) {
this.productUnitPrice = productUnitPrice;
}
public int getReorderLevel() {
return reorderLevel;
}
public void setReorderLevel(int reorderLevel) {
this.reorderLevel = reorderLevel;
}

}
96 changes: 96 additions & 0 deletions wipro/sales/dao/SalesDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package dao;

import bean.*;
import java.util.*;
import java.sql.*;
import util.*;

public class SalesDao {

//method 1
public int insertSales(Sales sales) throws Exception {
Connection con = null;
PreparedStatement ps = null;
String sql = "INSERT INTO TBL_SALES VALUES(?, ?, ?, ?, ?)";

java.sql.Date sqlDate = new java.sql.Date(sales.getSalesDate().getTime());

try {
con = DBUtil.getDBConnection();
ps = con.prepareStatement(sql);
ps.setString(1, sales.getSalesID());
ps.setDate(2, sqlDate);
ps.setString(3, sales.getProductID());
ps.setInt(4, sales.getQuantitySold());
ps.setDouble(5, sales.getSalesPricePerUnit());

if (ps.executeUpdate() == 1) return 1;
else return 0;
} catch (SQLException e) {
e.printStackTrace();
return 0;
}
}

//method 2
public static String generateSalesID(java.util.Date salesDate) throws Exception {
Connection con = null;
PreparedStatement ps = null;
String sql = "SELECT SEQ_SALES_ID.NEXTVAL FROM DUAL";

int SEQ_SALES_ID = 0;
String out = salesDate.toString().substring(salesDate.toString().length()-2, salesDate.toString().length());

try {
con = DBUtil.getDBConnection();
ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();

rs.next();
SEQ_SALES_ID = rs.getInt(1);

out += SEQ_SALES_ID;
return out;
} catch (SQLException e) {
e.printStackTrace();
return null;
}

}

//method 3
public ArrayList<SalesReport> getSalesReport() throws Exception{
Connection con = null;
PreparedStatement ps = null;
String sql = "SELECT * FROM V_SALES_REPORT";

ArrayList<SalesReport> list = new ArrayList<SalesReport>();

try {
con = DBUtil.getDBConnection();
ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();

int i=0;
while (rs.next()) {
SalesReport salesReport = new SalesReport();
salesReport.setSalesID(rs.getString(1));
salesReport.setSalesDate(rs.getDate(2));
salesReport.setProductID(rs.getString(3));
salesReport.setProductName(rs.getString(4));
salesReport.setQuantitySold(rs.getInt(5));
salesReport.setProductUnitPrice(rs.getDouble(6));
salesReport.setSalesPricePerUnit(rs.getDouble(7));
salesReport.setProfitAmount(rs.getDouble(8));
list.add(salesReport);

System.out.println(list.get(i).getSalesID()+" "+list.get(i).getSalesDate()+" "+list.get(i).getProductID()+" "+list.get(i).getProductName()+" "+list.get(i).getQuantitySold()+" "+list.get(i).getProductUnitPrice()+" "+list.get(i).getSalesPricePerUnit()+" "+list.get(i).getProfitAmount());
++i;
}
i=0;
} catch (SQLException e) {e.printStackTrace();return null;}

return list;

}
}
Loading