Hello friends,
I am new to Jsp
Here am facing a problem while trying to retrieve the data from ms access db using student no(number)
form.jps
=========
<html><head>
<BODY style="background-color:SteelBlue">
<center>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<form method="post" action="search.jsp"><h3>
Enter Ur Number: </h3><input type="text" size="3" name="no"><br />
<p><input type="submit" value="Submit">
</form>
</center>
</body>
</html>
============
search.jsp
================================
<%@ page import="java.sql.*" %>
<html>
<BODY style="background-color:SteelBlue">
<form>
<table border="1">
<tr><th>No</th><th>Name</th><th>qual</th></tr>
<%
int num=Integer.parseInt(request.getParameter("no")); // no is student id taken from
form.jsp eg no=1
//String num=request.getParameter("no");
//int x= Integer.parseInt(num);
%>
<%
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:student");
//out.println("connection ok");
String query= "select *from student where no=' " +num+" ' ";
stmt=con.createStatement( );
rs= stmt.executeQuery(query);
}
catch(Exception e)
{
out.println("error" +e);
}%>
<!-- <table cellpadding="15" border="1" style="background-color: #ffffcc;">
<tr><td>No:</td><td>Name:</td><td>Qualification:</td></tr>
-->
<% while(rs.next())
{
%>
<tr><td><input type="text" name="no" value="<%=rs.getInt("no")%>" ></td>
<td><input type="text" name="no" value="<%=rs.getString("nam")%>" ></td>
<td><input type="text" name="no" value="<%=rs.getString("qual")%>"></td></tr>
<%
}%>
<br>
<% rs.close();
stmt.close();
con.close();
%>
</table>
</form>
<form action="view.html" method="get" ><input type="submit" value="Go Home"/></form>
</body>
</html>
===============
I create Student db in ms access and in that i created three fields that are no,nam and qual. when am trying to search the student detail by no(number) the output on web page is not displaying.
But when am search by nam or qual it displaying the output on to the web page.
thanks in advance,
Abrar