Ex.No:2.
3b
Date:
To Create a College Management System using
Servlets with Jdbc
Question:
Develop a web application using HTML &Servlets for the given scenario below:
(Required database tables implementation must be done)
Consider you need to create a module in the project College Management system. In your
module you need to create the option for new staff registration by getting the staffs Name,
employee no, qualification and designation from the admin. You have to include the facility to
store and maintain all the details in database table. To give the conformation to the admin about
new faculty registration, print the staffs registration details at the end of your module execution.
Implement your module.
Aim:
To create a module in the project College Management system and perform the given
operations.
Program:
<!DOCTYPE html>
<html>
<head>
<title>LIBRARY MANAGEMENT SYSTEM</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form name="BOOK" method="get" action="http://localhost:8080/twopointthree/dbtwo">
<h1>LIBRARY MANAGEMENT SYSTEM </h1><br><h3>ACCESS NUMBER</h3>
<BR>
<pre>
ENTER BOOK ACCESS NUMBER
<input type="text" name="book"
id="1"><br>
<input type="submit" value="submit"/>
<input type="reset" value="reset"/>
</pre>
</form>
</body>
</html>
PROGRAM 2:
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class dbtwo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String book=request.getParameter("book");
Connection con = null;
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
con =DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
Statement st = con.createStatement();
String q="drop table book";
st.execute(q);
q= "create table book(bname varchar(20),access varchar(6),author varchar(20),publisher
varchar(20),price varchar(5))";
st.execute(q);
q="insert into book values('JAVA','350','schildt','TATA','500')";
st.executeUpdate(q);
q="insert into book values('C','240','schildt','TATA','500')";
st.executeUpdate(q);
q="insert into book values('C#','300','schildt','TATA','500')";
st.executeUpdate(q);
q="insert into book values('C++','330','schildt','TATA','500')";
st.executeUpdate(q);
q="select * from book where access='"+book+"'";
ResultSet r = st.executeQuery(q);
while(r.next())
{
out.println("<html><head></head><body>");
out.println("<table border='3'><tr bgcolor='CCFF66'><th>BOOK
NAME</th><th>ACCESS
NUMBER</th><th>AUTHOR</th><th>PUBLISHER</th><th>PRICE</th></tr>");
out.println("<tr bgcolor='gold'>");
out.println("<td>"+r.getString("bname")+"</td>");
out.println("<td>"+r.getString("access")+"</td>");
out.println("<td>"+r.getString("author")+"</td>");
out.println("<td>"+r.getString("publisher")+"</td>");
out.println("<td>"+r.getString("price")+"</td></tr>");
out.println("</table></body></html>");
}
}
catch(SQLException e)
{
out.println(e);
}
catch(ClassNotFoundException e)
{
out.println(e);
}
catch(Exception e)
{
out.println(e);
}
finally
{
try {
con.close();
} catch (Exception ex) {
Logger.getLogger(dbone.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Output:
Result:
Thus the project College Management system was created and performed the given
operations successfully.