♠ Posted by Unknown in Adv Java at 07:42
DataBase Connectivity on Servlet
This example is showing the DataBase connectivity to fetch the result of particular student from the SQL Table. DataBase may resides on server-side and establish ODBC connection between database and Java class.
Write a Servlet program to display the mark-sheet
of a particular student.
Seatno.html
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> MCA-III Result Display
</TITLE>
<META NAME="Generator"
CONTENT="EditPlus">
<META NAME="Author"
CONTENT="">
<META NAME="Keywords"
CONTENT="">
<META NAME="Description"
CONTENT="">
</HEAD>
<BODY>
<FORM METHOD = "POST" ACTION
= "http://localhost:8080/servlet/MCAServlet6">
<CENTER>
<H1>MCA-III
Result Display</H1>
</CENTER>
Enter
Seat No. for Display Result : - <INPUT TYPE = "TEXT" NAME =
"txtSeatNo">
<BR><BR>
<CENTER>
<INPUT
TYPE = "SUBMIT" VALUE = "Submit Here">
</CENTER>
</FORM>
</BODY>
</HTML>
MCAServlet6.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Connection;
public class MCAServlet6 extends
HttpServlet
{
String
dbUrl = "jdbc:odbc:Result";
String
user = "";
String
password = "";
Connection
c;
Statement
s;
ResultSet
r;
String
sno = "111";
String
nm = "Viral" , j2ee , sp , or , ds , total ;
public
void init()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c
= DriverManager.getConnection(dbUrl, user, password);
s
= c.createStatement();
r
= s.executeQuery("Select * From Result_Mst");
r.first();
}catch(Exception
e){}
}
public
void service(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException
{
res.setContentType("text/html");
PrintWriter
out = res.getWriter();
try
{
r
= s.executeQuery("Select * from Result_Mst");
r.first();
nm
= r.getString("Name");
j2ee
= r.getString("J2EE");
sp
= r.getString("SP");
or
= r.getString("OR");
ds
= r.getString("DS");
total
= r.getString("Total");
out.println("<BODY><H1
ALIGN = CENTER>" + nm +"</H1>");
}catch(Exception
e){}
out.println("<HTML><HEAD><TITLE>Student
Result Sheet</TITLE></HEAD>");
out.println("<BODY><H1
ALIGN = CENTER>Student Result Sheet</H1>");
out.println("<TABLE
BORDER=2><TR><TD COLSPAN = 2>Seat No. : " + sno + "
" + nm + "</TD></TR>");
out.println("<TR><TD
COLSPAN = 2>Collage Name : Computer Department</TD></TR>");
out.println("<TR><TD>Subject</TD><TD>Marks</TD></TR>");
out.println("<TR><TD>J2EE</TD><TD>"
+ j2ee + "</TD></TR>");
out.println("<TR><TD>System
Programming </TD><TD>" + sp +
"</TD></TR>");
out.println("<TR><TD>Operation
Research </TD><TD>" + or +
"</TD></TR>");
out.println("<TR><TD>Data
Structure </TD><TD>" + ds +
"</TD></TR>");
out.println("<TR><TD>Total
: </TD><TD>" + total + "</TD></TR>");
out.println("</TABLE>");
out.close();
}
}
1 comments:
How to get a room at the Casino (or Blackjack) in Las Vegas
Rooms 정읍 출장마사지 at the Casino (or Blackjack) · 부산광역 출장안마 Open the door for two. · 공주 출장샵 The casino 원주 출장안마 may 경상남도 출장안마 not offer casino games but you should also take advantage of free spins which
Post a Comment