| | |
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 |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






