Skip to main content

MCS-051,June, 2010 ,

Write a web application for a online support 20 of a video library. This application should have the following features :
  • Add a new video information in the library.
  • Check in / check out process for renting purpose.
  • Status report containing the current
  • status of videos in the library.

You are required to use the following tables for your online video library.





 <html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>Add new Customer : </div>
        <form action="AddNewCustomer" method="POST">
            Id : <input type="text" name="id" value="" /><br/>
            Name : <input type="text" name="name" value="" /><br/>
            Address : <input type="text" name="address" value="" /><br/>
            Registration date : <input type="text" name="reg_date" value="" /><br/>
            <input type="submit" value="Add" />
        </form>
    </body>
</html>

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AddNewCustomer extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String address = req.getParameter("address");
        String reg_date = req.getParameter("reg_date");

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
            PreparedStatement st = con.prepareStatement("insert into customer values(?,?,?,?)");
            st.clearParameters();
            st.setInt(1,  Integer.parseInt(id));
            st.setString(2, name);
            st.setString(3, address);
            st.setString(4, reg_date);
            st.executeUpdate();
            con.close();
             out.write("<h1>Customer Added to system</h1>");
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
            if(ex.getMessage().contains("General error"))
            out.write("Id value is already used.");
        }
       

    }
}


============================================================================
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>Add video to library : </div>
        <form action="AddNewVideo" method="POST">
            Id : <input type="text" name="id" value="" /><br/>
            Name : <input type="text" name="name" value="" /><br/>
            Genre : <input type="text" name="genre" value="" /><br/>
            Year of Release : <input type="text" name="year_of_release" value="" /><br/>
            Total Copies : <input type="text" name="Copies" value="" /><br/>
            <input type="submit" value="Add" />
        </form>
    </body>
</html>

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AddNewVideo extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String genre = req.getParameter("genre");
        String year_of_release = req.getParameter("year_of_release");
        String Copies = req.getParameter("Copies");
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
            PreparedStatement st = con.prepareStatement("insert into video_info values(?,?,?,?,?)");
            st.clearParameters();
            st.setInt(1,  Integer.parseInt(id));
            st.setString(2, name);
            st.setString(3, genre);
            st.setInt(4Integer.parseInt(year_of_release));
            st.setInt(5Integer.parseInt(Copies));
            st.executeUpdate();
            con.close();
             out.write("<h1>Video added to library</h1>");
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
            if(ex.getMessage().contains("General error"))
            out.write("Id value is already used.");
        }
       

    }
}

====================================================================================
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>check_in / check_out: </div>
        <form action="in_out" method="POST">
            Id : <input type="text" name="id" value="" /><br/>
            Customer Id : <input type="text" name="cust_id" value="" /><br/>
            Video Id:<input type="text" name="video_id" value="" /><br/>
            operation :<select name="operation">
                <option>Check-In</option>
                <option>Check-Out</option>
            </select><br/>
            transfer date : <input type="text" name="trans_date" value="<%= new java.util.Date() %>" /><br/>
            <input type="submit" value="Add" />
        </form>
    </body>
</html>



import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class in_out extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String id = req.getParameter("id");
        String cust_id = req.getParameter("cust_id");
        String video_id = req.getParameter("video_id");
        String operation = req.getParameter("operation");
        String trans_date = req.getParameter("trans_date");
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
            PreparedStatement st = con.prepareStatement("insert into trans values(?,?,?,?,?)");
            st.clearParameters();
            st.setInt(1Integer.parseInt(id));
            st.setInt(2Integer.parseInt(cust_id));
            st.setInt(3Integer.parseInt(video_id));
            st.setString(4, operation);
            st.setString(5, trans_date);
            st.executeUpdate();
            st.close();
            con.close();
            con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");

            Statement st1 = con.createStatement();
            ResultSet rs = st1.executeQuery("select total_copies from video_info where id=" + video_id);
            rs.next();
            int n = rs.getInt(1);
            if (operation.equalsIgnoreCase("Check-In")) {
                n++;
                int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
            } else {
                n--;
                int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
            }
            con.close();
            out.write("<h1>Transfer operation completed</h1>");
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
            if (ex.getMessage().contains("General error")) {
                out.write("Id value is already used.");
            }
        }


    }
}

==============================================================================
view status

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page  import ="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Status</title>
    </head>
    <body>
        <%

            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
                Statement st = con.createStatement();
                ResultSet rs = st.executeQuery("select * from video_info");
                String tr = "";
                while (rs.next()) {
                    tr = tr + "<tr>";
                    tr = tr + "<td>" + rs.getString(1) + "</td>";
                    tr = tr + "<td>" + rs.getString(2) + "</td>";
                    tr = tr + "<td>" + rs.getString(3) + "</td>";
                    tr = tr + "<td>" + rs.getString(4) + "</td>";
                    tr = tr + "<td>" + rs.getString(5) + "</td>";
                    tr = tr + "</tr>";
                }
                String table = "<table border='1'><tr><td>ID</td><td>Name</td><td>Genre</td><td>Year Of Release</td><td>Total Copies</td></tr>" + tr + "</table>";
                out.write(table);
                con.close();
            } catch (Exception e) {
                out.write("" + e);
            }
        %>
    </body>
</html>

======================================================================================
index.html

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>Welcome to video library application</h1>
        <a href="ViewStatus.jsp">View Status</a><a href="addCustomer.html">Add Customer</a><a href="addvideo.html">Add New Video</a><a href="chechkin_checkout.jsp">Checkin/Checkout</a>
    </body>
</html>

Comments

Popular posts from this blog

Using HyperSQL (HSQLDB)

HSQLDB is a portable RDBMS implemented in pure java. It can be embedded with your application as well as can be used separately. It is very a small database that supports almost all features of the standard database system. It comes with small jar file that can be found in lib folder. The HSQLDB jar package is located in the /lib directory of the ZIP package and contains several components and programs. Core components of jar file are : HyperSQL RDBMS Engine (HSQLDB), HyperSQL JDBC Driver, Database Manager, and Sql Tool. Installing and Using Download: download latest release of HyperSQL database from http://hsqldb.org website and extract it. You will see following contents. Here "bin" directory contains some batch files those can be used to run a swing based GUI tool. You can use runManagerSwing.bat to connect to database, but database must be on before running it. Directory lib contains File hsqldb.jar . It is the database to be used by you. Running database First

How to handle values from dynamically generated elements in web page using struts2

Some time you will see the form containing the button " Add More " . This facility is provided for the user to get the values for unknown number of repeating for some information. for example when you are asking to get the projects details from user, you need to put the option to add the more project for the user since you don't known how many projects user have. In the HTML form, you repeat the particular section to get the multiple values for those elements. In Html page , you can put the option to add new row of elements or text fields by writing the java script or using JQuery API. Now, the question is that how to capture the values of dynamically generated text fields on the server. Using the servlet programming you can get the values by using getParameters() method that resultants the array of the parameter having the same name. But this limit you to naming the text fields in the HTML form. To ally this approach, you have to take the same name for t

Generating JTable from database table

package  process; import  javax.swing. * ; import  javax.swing.table. * ; import  java.sql. * ; /**  * This class create JTable from Database table.  * User program needs to specify database connection and corresponding atable name.  * @author Hemraj  */ public   class  TableToJTable {      //private String table;      private   Connection  con;      public   TableToJTable ( Connection  con ){          this .con = con;      }      /**      * This method return JTable object created from Database table having same data asn structure      * as in original table into database.      * @param table Name of the database table to be coverted to JTable      * @return JTable object that consist of data and structure of Database table      * @throws java.lang.Exception Original object is deferent, e.i either SQLException or NullPointerException      */      public   JTable   getTable ( String  table ) throws   Exception {          JTable  t1 = new   JTable () ;          D