Trying to find ResultSet empty or not - Error - please help

Purpose of the code : I am trying to see if the customer or user is in the database.
Error : Cannote convert boolean to resultset
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%><%@page import = "java.sql.ResultSet"  %>
<%@page import = "java.sql.Connection"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Getting Database Connection</title>
</head>
<body>
     <%
     ResultSet result = null ;
   Connection connection1 = null;
  try
       String driverName1 = "oracle.jdbc.driver.OracleDriver";
      Class.forName(driverName1);
      String serverName = "localhost";
      String portNumber = "1521";
      String sid = "XE";
      String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
      String username = "SYSTEM";
      String password = "password";
      connection1 = DriverManager.getConnection(url, username, password);
      out.println(connection1.isClosed());
      String Name = request.getParameter("name");
      String Age = request.getParameter("age");
       int AgeConvert = Integer.parseInt(Age);
       String ADR = request.getParameter("address");
       String sqlInsert =  " INSERT INTO ADDRESS  (NAME,AGE,ADR)  VALUES ('" + Name + "' , " + AgeConvert + ", '" + ADR +"')";
       Statement stm = connection1.createStatement();
       stm.execute(sqlInsert);
       out.println(" User Created");
catch(Exception e )
     out.println("User not created");
     e.printStackTrace();
%>
<table>
  <tr>
  <td> <b>To search the User Please enter the name in the below box </b> </td>
  </tr>
  <tr>
  <td> Name </td>
  <td> <input type = "text" name ="userName" /> </td>
  </tr>
  <tr>
   <td> <input type ="submit" value = "Search" /></td>
   </tr>
  </table>
<%    ResultSet results = null ;
     String userNameToBeSearched = request.getParameter("userName");
     String sqlselect =  " SELECT * FROM ADDRESS WHERE NAME ='"+userNameToBeSearched+"'";
     Statement stm2 = connection1.createStatement();
     results = stm2.execute(sqlselect);
     if (results.next()) { 
         %>
         <TABLE BORDER="1">
            <TR>
               <TH>Name</TH>
               <TH>Age</TH>
               <TH>Address</TH>
            </TR>
           <TR>
               <TD> <%= results.getString(1) %> </TD>
               <TD> <%= results.getInt(2) %> </TD>
               <TD> <%= results.getString(3) %> </TD>
          </TR>
       </TABLE>
     <%    
     } else
    out.println("User not found");
     %>
</body>
</html>

DrClap wrote:
jverd wrote:
Better still, use PreparedStatement and its parameters, rather than trying to escape/quote stuff yourself. I can't think of a single case where there's any good reason to use Statement rather than PreparedStatement. (Though I'm sure somebody will come up with one.)
Also, don't put Java code in a JSP. Certainly not DB access code. Icky bad.And don't leave your connection open after you've finished using it. Close it in a finally block to make sure it gets closed no matter what.
And you should be using a connection pool in a web application rather than repeatedly opening and closing connections. Let the container handle the pool and get your connections from it via JNDI.
There we go. That's the usual lot of bad practices, isn't it? I don't think we missed any......and I would like to add this...dont do these type of business logic in a jsp. It is just a view...these works are of controllers'. You should follow MVC rules unless you want to fell in some real problems .

Similar Messages

Maybe you are looking for

  • Does anyone know how to upgrade from 4.1 to 4.3 ios?

    After being tricked by the fast talking smoothy helper at Apple store in London to buy a micky mouse ipodtouch (fourth generation) two years ago I am stuck at ios 4.1 and find that all the useful applications need 4.3 or more. So I went to the troubl

  • Subcontracting Process with Customer owned stock

    We are looking for SAP supported process where the customer sends us components along with a sales order for a finished good. The components have to be received into customer owned stock and will be used (for instance as part of the BOM) to produce t

  • Modify Self Profile in Request Failed status

    Hi, I have requiement to allow user to update his few details though Self-Service>My Profile> Attributes Update . System trigers an OOB approval to System Administrator for the Modify Self Profile , and on approval of task the attributes are getting

  • From Photoshop CS6, How do I render multiple files to Media Encoder when editing Video?

    I'm trying to send one version of my video open in PS CS6 to Media Encoder at 1920x1080 then while that renders, I'd like to crop it and render it as 1440x1080. Is there a faster way to to this? Ideally I'd like to Send it to ME rather than Export ri

  • CS6: how to update 12.0 to 12.2? [was: cs6 1200 updates]

    Hello I have cs6 Version 12.0 build 5861 I understand there is a later version 12.2 Build 6006. According to Help Updates the applications are all up to date. Can anyone say how I can get the latest updates please? Thank you John