How to search data JSp/Oracle

Mujtabadba
Mujtabadba used Ask the Experts™
on
Database : tere are two tables Students Fields ( Student_id,Roll_no,Enrollment,Name,father_Name)
anoter table is Result fields (Student_id,course_name, marks_th,marks_pr,grade_th,grade_pr,gp_th,gp_pr)

what i want to do is from Result.html student pass his roll no, i have to search student_id from student table then display the result of that particular id on result.jsp below is the detail code of student_id.jsp in which i just try to display the entered roll no details from student table but it does'nt display any record just display the headers.

<%@ page import="java.sql.*"%>
<HTML>
<HEAD><TITLE>Student </TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<%
Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:huexam","huhiit","allover#222");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT STUDENT_ID,ROLL_No,NAME,FATHER_NAME FROM huiit.STUD where Roll_no='Roll'");
// roll is the name of text field at html page
out.println("<TABLE CELLSPACING=\"0\" CELLPADDING=\"3\" BORDER=\"1\">");
out.println("<TR><TH>Student_id</TH><TH>Roll_No</TH>"); // this data displayed Only
out.println("<TH>Name</TH><TH>Father_Name</TH></TR>"); // This data displayed Only
//problem Area
while(rs.next())
{
out.println("<TR>");
out.println(" <TD>" + rs.getString("STUDENT_ID") + "</TD>");
out.println(" <TD>" + rs.getString("ROLL") + "</TD>");
out.println(" <TD>" + rs.getString("NAME") + "</TD>");
out.println(" <TD>" + rs.getString("FATHER_NAME") + "</TD>");
out.println("</TR>");
}
out.println("</TABLE>");
}
catch(SQLException e)
{
out.println("SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "<BR>");
}
catch(ClassNotFoundException e)
{
out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");
}
finally
{
if(conn != null)
{
try
{
conn.close();
}
catch (Exception ignored) {}
}
}
%>
</CENTER>
</BODY>
</HTML>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

try to look at the form action that u r trying, and the object values that are passed ...
Its some thing to do with your form submission...

R.K
In this part of your code:
stmt.executeQuery("SELECT STUDENT_ID,ROLL_No,NAME,FATHER_NAME FROM huiit.STUD where Roll_no='Roll'");// roll is the name of text field at html page

it looks like you want Roll_no='Roll' to limit on based on the Roll number entered by the user in the previous page.  the way it is now will simply send SELECT STUDENT_ID,ROLL_No,NAME,FATHER_NAME FROM huiit.STUD where Roll_no='Roll'   to the data base. And unless there is a Roll_no with a value of 'Roll' you would not return any records.  So the while(rs.next()) would never be entered.          
 
Try this:
String rollNo=request.getParameter("roll");//gets the parameter named roll entered by the user in the previous page
stmt.executeQuery("SELECT STUDENT_ID,ROLL_No,NAME,FATHER_NAME FROM huiit.STUD where Roll_no='"+rollNo+"'");
Commented:
This statement
ResultSet rs = stmt.executeQuery("SELECT STUDENT_ID,ROLL_No,NAME,FATHER_NAME FROM huiit.STUD where Roll_no='Roll'");

should be:

String rollNo = request.getParameter("Roll");
ResultSet rs = stmt.executeQuery("SELECT STUDENT_ID,ROLL_NO,NAME,FATHER_NAME FROM huiit.STUD where Roll_no="+rollNo);

Also, this
out.println(" <TD>" + rs.getString("ROLL") + "</TD>");
should be
out.println(" <TD>" + rs.getString("ROLL_NO") + "</TD>");

Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
I have already try this and found the problem in passing text value to jsp page then i see example from Wrox JSP to do this and find the solution of my problem .

But still the problem is how to or whom to i have to given points??? Kindly dont mind ...

Commented:
Give the points to those whose answers have helped you.

Author

Commented:
Thanks for all who HElp me in this problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial