Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UpdateQuantity() – Updates the quantity of a Part in stock by increasing or decr

ID: 3834013 • Letter: U

Question

UpdateQuantity() – Updates the quantity of a Part in stock by increasing or decreasing quantity
on hand.

// Update Part Quantity
public static int UpdateQuantity(int qtyChange, Part p)
{
// Declare an int to contain a count of records affected by operation
int records = 0;
// Declare and set sql statement string to update Quantity in DB
// for Part p using ID. New Quantity reflect the change in Quantity
// in qtyChange
  
// Execute update - set records to count affected
  
// Return number of records affected
return records;
}

All Access Obje EEE tblTransactions EE tblParts fldMake fldName fld Price fldQuantity Click to Add fldID Search... $120.00 Chevrolet Radiator Tables $12.00 2 Chevrolet Fan Belt 40 EEE tbl Parts. 3 Chevrolet Tail Lamp Bulb $5.00 45 EEE tbITransactions Head Light $15.00 4 Chevrolet 30 25 $65.00 5 Chevrolet Battery $10.00 6 Chevrolet Air Filter

Explanation / Answer

In java we use JDBC to connect with database. Steps to connect to database using JDBC are specified below.

Assuming that your database name is tblParts and column names are fldID and fldQuantity code for updating quantity is given below.

Enter your database driver class name, url , username and password.

public static int UpdateQuantity(int qtyChange, Part p)
{
// Declare an int to contain a count of records affected by operation
int records = 0;          
           //step1 load the driver class
           Class.forName("Yur database driver");
           //step2 create the connection object
           Connection con=DriverManager.getConnection("your database url","username","password");
           //step3 create the statement object
           Statement stmt=con.createStatement();
           String sql = "UPDATE Registration tblParts SET fldQuantity = "+qtyChange+" WHERE fldID="+p;
           records= stmt.executeUpdate(sql);
return records;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote