Pages

Ads 468x60px

Friday 21 December 2012

Week-11 Extract data from the tables,display them in the catalogue page using JDBC



Week-11:                                                                                               Date:
------------------------------------------------------------------------------------------------------------
AIM: Extract data from the tables and display them in the catalogue page using JDBC.
DESCRIPTION:
            Create tables in the database which contain the details of items (books in our case like Book name, Price, Quantity, Amount)) of each category. Modify your catalogue page (week 2) in such a way that you should connect to the database and extract data from the tables and display them in the catalogue page using JDBC.

PROGRAM:
Retrieve.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Retrieve extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:cclab","scott","tiger");
Statement s=con.createStatement();
ResultSet r=s.executeQuery("select * from cart");
out.println("<center> <table border=1>");
out.println("<thead> <th> Book name </th> <th> Price </th> <th> Quantity </th> <th> Amount </th> </thead>");
while(r.next())
{
out.println("<tr> <td> "+r.getString(1)+"</td> ");
out.println("<td> "+r.getString(2)+"</td> ");
out.println("<td> "+r.getInt(3)+"</td> ");
out.println("<td> "+r.getString(4)+"</td> </tr>");
}
out.println("</table></center>");
con.close();
}
catch(SQLException sq)
{
out.println("sql exception"+sq);
}

catch(ClassNotFoundException cl)
{
out.println("class not found"+cl);
}
}
}

web.xml:
<web-app>
<servlet>
<servlet-name>set</servlet-name>
<servlet-class>Cartenter</servlet-class>
</servlet>
<servlet>
<servlet-name>display</servlet-name>
<servlet-class>Retrieve</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>set</servlet-name>
<url-pattern>/enterdata</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>display</servlet-name>
<url-pattern>/display1</url-pattern>
</servlet-mapping>
</web-app>
http://wikibrand.blogspot.in
CREATE THE TABLE AND INSERT VALUES INTO THE TABLE:                                  
http://wikibrand.blogspot.in
OUTPUT:
http://wikibrand.blogspot.in

RESULT:
The data is extracted from the tables and displayed in the catalogue page using JDBC
SOURCE :PVPSIT FOR JNTU

1 comments:

  1. hi wikibrand,
    can you post the lab answers for the following question-
    Shanmukh has 10 theatres in AP. Every theatre is managed by a manager. Due to covid19 the risk of virus spread may increase among the customers and theatre staff. So, Shanmukh wants to digitalize the ticket booking process so that there will be no rush at the ticket counter and the risk of spread was minimal.

    As you are a computer science student, he approached you to help him out to build a web application where customers can book tickets online.

    Shanmukh’s requirements are as below:

    a. Shanmukh (super admin) can add the managers of his theatres(admin)

    b. Admin can login with their own credentials and add movie details into database

    c. Customer should login with his registered credentials.

    d. Customers must have a provision to book the ticket(s) (He can update no of tickets) for a respective movie. At the last moment, if customer is not willing to go to theatre, he should have a provision to cancel the ticket he booked

    e. Shanmukh must have a provision to view how many tickets are sold and how much money earned.

    Create a web application as per his requirements by using servlets.

    ReplyDelete

 

Sample text

Sample Text

Sample Text