Results 1 to 4 of 4
Thread: Retrieval Problem
- 11-16-2012, 07:54 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Retrieval Problem
Hi friends, I am working on a project and I am having a problem in retrieving the data from the database in a jsp page.
My application prompts for a user-id(varchar2) and checks it with the data in the data base and retrieves the matching rows.
But it is not fetching the rows if the user-id is varchar2 and it is fetching the rows if user-id is number.
help me with this problem
plz........
HOME PAGE<HTML>
<HEAD>
<TITLE>Database Lookup</TITLE>
</HEAD>
<BODY>
<H1>Database Lookup</H1>
<FORM ACTION="index.jsp" METHOD="POST">
Please enter the ID of the publisher you want to find:
<BR>
<INPUT TYPE="TEXT" NAME="id">
<BR>
<INPUT TYPE="SUBMIT" value="Submit">
</FORM>
</BODY>
</HTML>
JSP PAGE
<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<HTML>
<HEAD>
<TITLE>Fetching Data From a Database</TITLE>
</HEAD>
<BODY>
<H1>Fetching Data From a Database</H1>
<%
Connection connection = DriverManager.getConnection(
"jdbc:odbc:pardhu", "scott", "tiger");
Statement statement = connection.createStatement();
ResultSet resultset =
statement.executeQuery("select * from mca1 where no = "+request.getParameter("id")) ;
if(!resultset.next()) {
out.println("Sorry, could not find that publisher. ");
} else {
%>
<TABLE BORDER="1">
<TR>
<TH>ID</TH>
<TH>Name</TH>
<TH>Gender</TH>
<TH>City</TH>
</TR>
<TR>
<TD> <%= resultset.getString(1) %> </TD>
<TD> <%= resultset.getString(2) %> </TD>
<TD> <%= resultset.getString(3) %> </TD>
<TD> <%= resultset.getString(4) %> </TD>
</TR>
</TABLE>
<BR>
<%
}
%>
</BODY>
</HTML>
- 11-16-2012, 09:23 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Retrieval Problem
Please use [code] tags [/code] when posting code.
Unformatted code is hard to read.
First off, you should not be doing this sort of thing in a JSP. This should be done in a servlet which would then forward to the relevant JSP, a succes one for a valid id and a failure one for an invalid id. However, I realise some tutors seem to start with JSPs. They are idiots.
Second, you are getting an exception but you either haven't told us what it is or you are eating it.
Third, you should really be using a PreparedStatement. The tutorial page is here. Should you not want to use one (and you should, but again depends on what you've learned) then you'll need to add single quotes around your parameter to make that a valid SQL statement.Please do not ask for code as refusal often offends.
- 11-16-2012, 09:25 PM #3
Re: Retrieval Problem
Moved from NetBeans.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-19-2012, 07:45 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Retrieval problem
By pardhu in forum JDBCReplies: 2Last Post: 11-12-2012, 10:54 AM -
Image retrieval
By KiranA in forum New To JavaReplies: 1Last Post: 07-11-2011, 07:29 PM -
URL retrieval using swings
By gbose in forum AWT / SwingReplies: 1Last Post: 02-07-2010, 02:19 PM -
web image retrieval
By ak88 in forum New To JavaReplies: 3Last Post: 01-05-2010, 11:37 AM -
retrieval of tags
By mahalakshmi in forum New To JavaReplies: 1Last Post: 02-23-2009, 12:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks