16. Assume that the information regarding the marks for all the subjects of a student in the last exam are available in a database, Develop a Servlet which takes the enrollment number of a student as a request parameter and displays the marksheet for the student.
1. Create Database in MySql / Oracle / Access
You can choose any database. Here, I provide the solution to connect database like MySQL, Oracle, and Microsoft Access
2. Create Table IN MySQL
create table MARK (EnNo VARCHAR(10),Code VARCHAR(10),Name VARCHAR(10),Mark INT(3));
3. Create Table IN Oracle
3. Create Table IN Oracle
create table MARK (EnNo VARCHAR(10),Code VARCHAR(10),Name VARCHAR(10),Mark NUMBER (3));
4. Create Web Application in tomcat using following code
index.jsp
<HTML>
<HEAD>
<TITLE>Ex-16 : www.BipinRupadiya.blogspot.in</TITLE>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>
</HEAD>
<BODY>
<div class="abc" id="f1">
<br>
<center>
<h3>
<FORM METHOD=POST ACTION="Ex16.com">
Enrollment No.: <input type=TEXT name = "txtEnNo" >
<BR><BR><input type="submit" value="Show Result">
</FORM>
</div>
</BODY>
</HTML>
Ex16.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.servlet.annotation.WebServlet;
@WebServlet("/Ex16.com")
public class Ex16 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String enNo = request.getParameter("txtEnNo");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
//Connect To MySql
/* Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wtad","root","admin");
*/
//Connect To Oracle
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");
//Connect To Access
/*
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:test","bipin","rupadiya");
*/
String sql = "select * from MARK where EnNo = ?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, enNo);
ResultSet rs= ps.executeQuery();
out.println("<HTML><BODY bgcolor='#ababff'>");
out.println("<center><h1> Marksheet</h1>");
out.println("<TABLE BORDER=1 cellpadding='5px' width=50%");
out.println("<TR><TH colspan=3> Enrollment No.:"+enNo+"</TH></TR>");
out.println("<TR><TH>CODE </TH> <TH>NAME </TH> <TH> GRADE </TH></TR>");
if(rs == null)
{
out.println("<h1> Result Not Found... </h1>");
}
else
{
while(rs.next())
{
out.println("<TR>");
out.println("<TD>"+rs.getString(2)+"</TD>");
out.println("<TD>"+rs.getString(3)+"</TD>");
out.println("<TD>"+rs.getInt(4)+"</TD>");
out.println("</TR>");
}
out.println("<TR><TH colspan=3> <a href='index.jsp'>Home</a> </TH></TR>");
out.println("</TABLE></CENTER></BODY></HTML>");
rs.close();
ps.close();
con.close();
}
}
catch(SQLException e)
{
out.println(e);
}
catch(ClassNotFoundException e)
{
out.println(e);
}
catch(Exception e)
{
out.println(e);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request, response);
}
}
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
Post a Comment