DBMS
Query
Create
table rookbook(
RoomId
varchar(4) PRIMARY KEY,
RoomType
varchar(20),
charges
number(5,2),
cust
varchar(20),
mob
varchar(20) ,
status
varchar(10)
);
insert
into roombook values('1001','Delux',5000.00,'','','Not Booked');
insert into
roombook values('1002','Super Delux',7000.00,'','','Not Booked');
insert into
roombook values('1003','Suit',9500.00,'','','Not Booked');
insert into
roombook values('2001','Delux',5000.00,'','','Not Booked');
insert into
roombook values('2002','Super Delux',7000.00,'','','Not Booked');
insert into
roombook values('2003','Suit',9500.00,'','','Not Booked');
-------------------------------------RoomBook.html
------------------------------------
<form
action="RBServlet" >
Select
a room Type
<input
type="radio" name="txtType"
value="Delux">Delux
<input
type="radio" name="txtType" value="Super
Delux">
Super
Delux
<input type="radio" name="txtType"
value="Suit">
Suit<br>
Enter
Your Name
<input
type="text" name="txtCust" ><br>
Enter
Mobile No.<input type="text" name="txtMob"
><br>
<input
type="reset" >
<input
type="submit" value="Book Room">
</form>
------------------------------------------RBServlet--------------------------------------
package mypack;
import java.io.*;
import
javax.servlet.*;
import
javax.servlet.http.*;
import
javax.ejb.EJB;
import mybeans.RRBean;
public class
RBServlet extends HttpServlet {
@EJB RRBean obj;
public void
doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException{
PrintWriter
out=response.getWriter();
String
rt=request.getParameter("txtType");
String
cn=request.getParameter("txtCust");
String
cm=request.getParameter("txtMob");
String msg =
obj.roomBook(rt, cn, cm);
out.println(msg);
}
}
-------------------------------------------RRBean.java
----------------------------------
package mybeans;
import
javax.ejb.Stateless;
import java.sql.*;
@Stateless
public class RRBen
{
public RRBean(){}
public String
roomBook(String rt, String cn, String cm){
String
msg="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/rrdb","root","root");
String
query="select * from roombook where RoomType=? and status='Not
Booked'";
PreparedStatement
pst = con.prepareStatement(query); pst.setString(1,rt);
ResultSet rs=
pst.executeQuery();
if(rs.next()){
String
rno=rs.getString(1);
PreparedStatement
stm1 = con.prepareStatement("update roombook set cust=? where RoomId=?
");
PreparedStatement
stm2 = con.prepareStatement("update roombook set mobile=? where RoomId=?
");
PreparedStatement tm3
= con.prepareStatement("update roombook set status=? where RoomId=?
");
stm1.setString(1,cn); stm1.setString(2,rno);
stm2.setString(1,cm); stm2.setString(2,rno);
stm3.setString(1,
"Booked"); stm3.setString(2,rno);
stm1.executeUpdate();
stm2.executeUpdate();
stm3.executeUpdate();
msg = "Room
"+rno+ " Booked <br> Charges = "+rs.getString(3);
}
else
{
msg = "Room
"+rt+ " currently Not available";
}
}catch(Exception
e){msg=""+e;}
return msg;
}
}
Comments
Post a Comment