JSP Problem Student database search

Reply

Join Date: Aug 2006
Posts: 3
Reputation: kssprabhu is an unknown quantity at this point 
Solved Threads: 0
kssprabhu kssprabhu is offline Offline
Newbie Poster

JSP Problem Student database search

 
0
  #1
Aug 19th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JSP Problem Student database search

 
0
  #2
Aug 19th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: JSP Problem Student database search

 
0
  #3
Aug 20th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC