Results 1 to 4 of 4
  1. #1
    pardhu is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default 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>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Retrieval Problem

    Moved from NetBeans.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    pardhu is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

Similar Threads

  1. Retrieval problem
    By pardhu in forum JDBC
    Replies: 2
    Last Post: 11-12-2012, 10:54 AM
  2. Image retrieval
    By KiranA in forum New To Java
    Replies: 1
    Last Post: 07-11-2011, 07:29 PM
  3. URL retrieval using swings
    By gbose in forum AWT / Swing
    Replies: 1
    Last Post: 02-07-2010, 02:19 PM
  4. web image retrieval
    By ak88 in forum New To Java
    Replies: 3
    Last Post: 01-05-2010, 11:37 AM
  5. retrieval of tags
    By mahalakshmi in forum New To Java
    Replies: 1
    Last Post: 02-23-2009, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •