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 !!!<br><hr>
<%
query_person = "select * from Authenticate where Per_id = " + rs.getInt("Per_ID") + " ";
}
else
{
%> Student does Not exist !!!<br>

<%
}
%>
<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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.