Attached files httpswwwdropboxcomshqngwy0jvsglgadqAAAeVpn9uv

Attached files:

https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0

For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?dl=0

Complete a Java program named InventoryMgr that maintains products in a database.

The code to initialize the ProductDB database table and add a set of products is provided.

Finish the code needed in these methods in ProductDB.java to update or query the database:

purchased(int quantityPurchased)

sold(int quantitytSold)

getDescription()

Hint: Look at the getPrice() and getQuantity() methods to see how you might write the getDescription() method’s code, and the addProduct() method to see an example of how you might write the code for the purchased() and sold() methods.
Download the derby.jar file and save it where Eclipse can use it, such as on your Desktop.

Download the Homework4Files.zip file containing these files:

database.properties

Properties file for the database connection

ProductDB.java

Class to update and query productdb rows

InventoryDB.java

Class to initialize the ProductsDB table and operate on all products

InventoryMgr.java

Main method with user interface

SimpleDataSource.java

SimpleDataSource class to simplify database connections

To run the InventoryMgr Java program in Eclipse, create a new project, copy all of the Java files into the src folder of your project, and copy the database.properties file into the project’s folder. Open the Project’s Properties dialog and select Java Build Paths, then click the Libraries tab. Click the Add JARs button, use the Open dialog to find the file derby.jar, and click the Open button. Click OK to save these changes to the Project’s properties.

Here is a sample run of the program – the user’s input is in green:

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

I

Enter \'YES\' if you wish to reinitialize the inventory:

YES

Notice: inserted product 116-064 Toaster 50 24.95

Notice: inserted product 257-535 Hair dryer 75 29.95

Notice: inserted product 643-119 Car vacuum 43 19.99

Notice: inserted product 011-025 Gallon 2% Milk 111 2.95

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

A

Enter new product code: 123-456

Enter new product description: Blender

Enter new product quantity: 5

Enter new product price: 14.95

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

P

Enter product code for purchase: 116-064

Product 116-064: Product: 116-064 Toaster 50 24.95

Enter number of products purchased: 5

Product 116-064 now has quantity 55.

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

S

Enter product code for sale: 643-119

Product 643-119: Product: 643-119 Car vacuum 43 19.99

Enter number of products sold: 3

Product 643-119 now has quantity 40.

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

C

Enter product code to check: 011-025

Product: 011-025 Product: 011-025 Gallon 2% Milk 111 2.95

I) Initialize database A)dd Product P)urchase Products S)ell Products C)heck Product L)list Products Q)uit

q

database.properties

Properties file for the database connection

ProductDB.java

Class to update and query productdb rows

InventoryDB.java

Class to initialize the ProductsDB table and operate on all products

InventoryMgr.java

Main method with user interface

SimpleDataSource.java

SimpleDataSource class to simplify database connections

Solution

another code by netbean ide

First of all we need to create sql table

insert data to MySQL using JSP

CREATE TABLE `inventory` (

  `id` int(10) unsigned NOT NULL auto_increment,

  `Product_name` varchar(45) NOT NULL,

  `Serial Number` varchar(45) NOT NULL,

  `Company_name` varchar(45) NOT NULL,

  `Quantity` varchar(45) NOT NULL,

  `Date_of_Purchase` date NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

User Form

<%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>

<!DOCTYPE html>

<html>

    <head>

        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">

        <title>JSP Example</title>

    </head>

    <body>

        <form method=\"post\" action=\"login.jsp\">

            <center>

            <table border=\"1\" width=\"30%\" cellpadding=\"3\">

                <thead>

                    <tr>

                        <th colspan=\"2\">Login Here</th>

                    </tr>

                </thead>

                <tbody>

                    <tr>

                        <td>User Name</td>

                        <td><input type=\"text\" name=\"uname\" value=\"\" /></td>

                    </tr>

                    <tr>

                        <td>Password</td>

                        <td><input type=\"password\" name=\"pass\" value=\"\" /></td>

                    </tr>

                    <tr>

                        <td><input type=\"submit\" value=\"Login\" /></td>

                        <td><input type=\"reset\" value=\"Reset\" /></td>

                    </tr>

                    <tr>

                        <td colspan=\"2\">Yet Not Registered!! <a href=\"reg.jsp\">Register Here</a></td>

                    </tr>

                </tbody>

            </table>

            </center>

        </form>

    </body>

</html>

login.jsp

<%@ page import =\"java.sql.*\" %>

<%

    String userid = request.getParameter(\"uname\");   

    String pwd = request.getParameter(\"pass\");

    Class.forName(\"com.mysql.jdbc.Driver\");

    Connection con = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/dbname\",

            \"root\", \"dbpass\");

    Statement st = con.createStatement();

    ResultSet rs;

    rs = st.executeQuery(\"select * from members where uname=\'\" + userid + \"\' and pass=\'\" + pwd + \"\'\");

    if (rs.next()) {

        session.setAttribute(\"userid\", userid);

        //out.println(\"welcome \" + userid);

        //out.println(\"<a href=\'logout.jsp\'>Log out</a>\");

        response.sendRedirect(\"success.jsp\");

    } else {

        out.println(\"Invalid password <a href=\'index.jsp\'>try again</a>\");

    }

%>

registration.jsp

<%@ page import =\"java.sql.*\" %>

<%

    String user = request.getParameter(\"Productname \");   

    String pwd = request.getParameter(\"SerialNumber \");

    String fname = request.getParameter(\"Companyname \");

    String lname = request.getParameter(\"Quantity\");

    String email = request.getParameter(\"DateofPurchase \");

    Class.forName(\"com.mysql.jdbc.Driver\");

    Connection con = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/dbname\",

            \"root\", \"dbpass\");

    Statement st = con.createStatement();

    //ResultSet rs;

    int i = st.executeUpdate(\"insert into members(Productname, SerialNumber, Companyname, Quantity, DateofPurchase) values (\'\" + productname + \"\',\'\" + serialnumber + \"\',\'\" + companyname + \"\',\'\" + quantity + \"\', CURDATE())\");

    if (i > 0) {

        //session.setAttribute(\"userid\", user);

        response.sendRedirect(\"welcome.jsp\");

       // out.print(\"Registration Successfull!\"+\"<a href=\'index.jsp\'>Go to Login</a>\");

    } else {

        response.sendRedirect(\"index.jsp\");

    }

%>

success.jsp

<%

    if ((session.getAttribute(\"userid\") == null) || (session.getAttribute(\"userid\") == \"\")) {

%>

You are not logged in<br/>

<a href=\"index.jsp\">Please Login</a>

<%} else {

%>

Welcome <%=session.getAttribute(\"userid\")%>

<a href=\'logout.jsp\'>Log out</a>

<%

    }

%>

logout.jsp

<%

session.setAttribute(\"userid\", null);

session.invalidate();

response.sendRedirect(\"index.jsp\");

%>

<%@ page import =\"java.sql.*\" %>

<%

    String userid = request.getParameter(\"uname\");   

    String pwd = request.getParameter(\"pass\");

    Class.forName(\"com.mysql.jdbc.Driver\");

    Connection con = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/dbname\",

            \"root\", \"dbpass\");

    Statement st = con.createStatement();

    ResultSet rs;

    rs = st.executeQuery(\"select * from members where uname=\'\" + userid + \"\' and pass=\'\" + pwd + \"\'\");

    if (rs.next()) {

        session.setAttribute(\"userid\", userid);

        //out.println(\"welcome \" + userid);

        //out.println(\"<a href=\'logout.jsp\'>Log out</a>\");

        response.sendRedirect(\"success.jsp\");

    } else {

        out.println(\"Invalid password <a href=\'index.jsp\'>try again</a>\");

    }

%>

Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?
Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?
Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?
Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?
Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?
Attached files: https://www.dropbox.com/sh/qngwy0jvsglgadq/AAAeVpn9_uvTBc4V67FdydLLa?dl=0 For derby: https://www.dropbox.com/s/e1up0e7wugomt07/derby%282%29.jar?

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site