954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JSP Problem Student database search

Dear all.
greetings
here is the code snippet for student database search.
whatever number i enter in the textbox,it says that student details r not found.
please verify it.

HTML code

<html>
<head>
<title>
Student Search
</title>
</head>
<body>
<form method="POST" action="http://localhost:7001/jsp/result.jsp">
<table align="center" width="50%" border="0" cellspacing="4" cellpadding="4">
<tr>
<th colspan="50" bgcolor="gray"><font face="arial" size="5px" color="black" align="left"><b>Student Details</b></font></th>
</tr>
<tr>
<td><font face="verdana" size="3px" color="black">Student Roll NO</font></td>
<td><input type="text" name="Per_ID" size="16"/>
<td colspan="50" align="left"><input type="submit" value="Search"/></td>

</tr>
</table>
</form>
</body>
</html>

JSP CODE

<%@ page language="java" 
import="java.sql.*,java.util.*" session="true" %>
<html>
<head>
<title>Student Details</title>
</head>
<body>
<% Connection con;
Statement stmt;
ResultSet rs;
String url = "Jdbc:Odbc:AMS1";
String query = "select * from Authenticate where Per_ID = " + request.getParameter("Per_ID") + " ";
String query_person = null;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
}
try
{
con = DriverManager.getConnection(url,"user","user");
stmt = con.createStatement();
rs = stmt.executeQuery(query);
if(rs.next())
{
%>
Student exists !!!<hr>
<%
query_person = "select * from Authenticate where Per_id = " + rs.getInt("Per_ID") + " ";
}
else
{
%> Student does Not exist !!!

<%
}
%>
<table border="1" align="left" width="60%">
<%
if(query_person != null || query_person != "")
{
rs = stmt.executeQuery(query_person);
while(rs.next())
{
%>
<tr>
<td>Person Identification</td>
<td>
<%= rs.getInt("Per_ID") %>
</td>
</tr>
<tr>
<td>Name [login_name, password]</td>
<td>
<%= rs.getString("Login_name") %>
,<%= rs.getString("Password") %>
</td>
</tr>

<tr>
<td>type</td>
<td>
<%= rs.getString("Type") %>
</td>
</tr>
</table>
<%
}
}
rs.close();
stmt.close();
con.close();

}
catch(Exception e)
{
}
%>
</body>
</html>

please verify this and offer ur valuable comments
thanks in advance
prabhu

kssprabhu
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

don't do that kind of stuff in a JSP. Use a proper application architecture, JSPs should be used for display only and NEVER use scriptlets.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

I agree with jwenting. Its a bad idea to do database programmiing in a jsp. But my guess is you won't stop doing it. So I would recommend puting system.out statements in your catchs to see if an exception is being thrown. I would also try and up your logging on your database to see exactly what is being requested. Overall, the logic looks ok, maybe the data being sent isn't correct.

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You