Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet How to write program to show status of seats(i.e.free or reserve) in java?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rakesh dilip patil
How to write program to show status of seats(i.e.free or reserve) in java?
1 Answer(s)      2 years and 7 months ago
Posted in : JSP-Servlet


I have retrieved data from database table and I want to display status of seats i.e.free or reserved.


Advertisement
View Answers

May 2, 2012 at 1:27 PM


1)bookSeat.jsp:

<%@page import="java.sql.*"%>
<html>
<form method="post" action="Place.jsp">
<table border="1">
<tr><th>Sno</th><th>Comp A</th><th>Comp B</th><th>Comp C</th><th>Comp D</th></tr>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement st=con.createStatement();
ResultSet rs= st.executeQuery("select * from seatbooking");
while(rs.next()){
%>
<tr><td><%=rs.getString(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><%=rs.getString(5)%></td><td></tr>

<%
}
%>
</table>
<table>
<tr><td>Enter Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Seat to Reserve:</td><td><input type="text" name="seat"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)Place.jsp:

<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String seat=request.getParameter("seat");
char ch1=seat.charAt(0);
char ch2=seat.charAt(1);
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement stmt=con.createStatement();
int i=stmt.executeUpdate("update seatbooking set code"+Character.toString(ch1)+"='booked' where no='"+Character.toString(ch2)+"'");
int j=stmt.executeUpdate("insert into seatinformation(name,seat) values('"+name+"','"+seat+"')");
response.sendRedirect("../jsp/bookSeat.jsp");
%>

For the above code, we have created 2 database tables 'seatbooking' and seatinformation:

CREATE TABLE `seatbooking` (
`no` bigint(255) NOT NULL auto_increment,
`codeA` varchar(255) default NULL,
`codeB` varchar(255) default NULL,
`codeC` varchar(255) default NULL,
`codeD` varchar(255) default NULL,
PRIMARY KEY (`no`)
)

CREATE TABLE `seatinformation` (
`id` bigint(255) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`seat` varchar(255) default NULL,
PRIMARY KEY (`id`)
)

You can also visit the following link:

Assign Seats



Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com