| | |
JSP Problem Student database search
![]() |
•
•
Join Date: Aug 2006
Posts: 3
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
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.
![]() |
Similar Threads
- ASP Search Database (ASP)
- Go to a certain page when button is pressed and do it securely (ASP.NET)
- Please help.... (C)
- error due to accessing database connection using jsp (JSP)
- JSP Error (JSP)
- [urgent] JSP problem (JSP)
- search and results problem (PHP)
Other Threads in the Java Forum
- Previous Thread: StringTokenizer
- Next Thread: Help............
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






