How to determine whether a recordset is Empty or not ?

Please see my snippet code below :
<%     
     String sql="";
     String username="CDS";
     try
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:Employees","","");
            Statement stmt = con.createStatement();
            ResultSet rs=null;
               sql = "Select * from Employee where code='" + username + "'";
               rs = stmt.executeQuery(sql);
               rs.next();
               if (rs==null)
               %>
                    <jsp:forward page="Login.jsp?msg=Username not recognized"></jsp:forward>     
               <%     
            else
               %>
                    <jsp:forward page="Login.jsp?msg=Halo"></jsp:forward>
               <%
          catch(ClassNotFoundException e)
               out.println("Driver not found");
                catch(SQLException e2)
                        out.println(e2.getMessage());
                        out.println("<BR>");
                        out.println("Wrong SQL Statement");
                        out.println("<BR>");
                        out.println(sql);
                        out.println("<BR>");
     %>How to determine whether a recordset has no result ?
From the above code, i use if (rs==null) and that's not worked.
Help me, guys.

ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
%>
    <jsp:forward page="Login.jsp?msg=Halo"/>
<%
} else {
%>
    <jsp:forward page="Login.jsp?msg=Username not > recognized"/>
<%
}

Similar Messages

  • How to determine whether process Chain is active or Not

    Hello Experts,
    How to determine whether process Chain is active or Not, because i have large number of PC to activate.

    Hi,
    Please check this program in SE38---- /SSA/BWT
    This program will give you information regarding all your process chains which are active and running based on there timings.
    Hope it helps.
    Regards,
    AL

  • How to check whether the Resultset is empty or not ??

    I wanna check whether my Result set is empty or not ( I don't want the no of rows it contains..) i'm using this function...
    boolean result=myResultSet.isAfterLast() | myResultSet.isBeforeFirst() ;
    if (result == true)
    {//Result Set is populated
    else
    {//ResultSet Blank
    Is it ok to do like this ?? Or is there any other functanality to do this, since in big appl..i'm using it more than 10-15 times & it's working fine evrywhere except for one jsp where it is returing TRUE everytime ...
    Help Appreciated !!

    try,
    rs = pstmt.executeQuery();
    boolean b = false;
    if( b = rs.next() ) {
    while( b ) {
    //... rs.getXXX( YYY );
    b = rs.next();
    else {
    //...empty rs processing
    or,
    ResultSet rs = ps.executeQuery();
    if(rs.next()) {
    do {
    System.out.println(rs.getString(1));
    } while(rs.next());
    } else {
    System.out.println('empty result set');
    but I usually avoid using do...while although this may be an exception.

  • How can we check whether a ResultSet is EMPTY or NOT ?

    i'm getting some data inside ResulSet (using JDBC inside Servlet).
    now i want to redirect response according to ResultSet...., if ResultSet is EMPTY then on diff page, else on different page...
    how can i check whether a ResultSet is empty or not...
    i've used next() , wasNull() methods ,,, but not solving the purpose...
    thanx in advance...

    What you could do is to ask the database fora
    record count and check that for zero.
    How?????You just do an SQL statement but instead of the list of fields after SELECT you put
    SELECT count(*) FROM ...... WHERE .....
    That returns a single integer value into the resultset giving the number of matching records currently in the database.
    The trouble is you can't be certain that when you subsequently access the records the number won't have changed, because databases are generally accessible to more than one process at a time and some other process might add or delete a record between counting and retrieving or, for that matter, during the process of retrieval.
    Also the count is likely to take more time than just doing rs.next() and seeing if you get a record.
    Since you seem to be in a servlet environment you should consider doing the database query and the first rs.next() at the top of the servlet/JSP that presents the results and, if there are no records, using getServletContext.getRequestDispatcher(...).forward(request, response) to swich to your error page if it returns false.
    So the stucture looks like:
    rs = stmt.executeQuery(......);
    if(!rs.next())
          getServletContext().getRequestDispatcher("/noresultspage.jsp").forward(request, response);
    else {
         do   {
             .... display result data
          } while(rs.next());
        }

  • How do I test if Dataset is empty or not

    I want to use the Spry:states, with the Spry:State="ready"
    div, holding a couple of Spy:if's, to display content, based on
    whether my dataset is empty or not. If it is empty I want to show a
    message. If the dataset has data, I will show my dynamic table.
    What is the syntax used to test whether I have data in my
    dataset? When Spry recieves a Dataset with empty values in the
    tags(XML) it still assumes the dataset is ready, so I need to test
    further, the contents.
    I have tried the following variations to no avail:
    <div spry:if="insSearchResults==0"> //testing if it is
    empty
    <div spry:if="insSearchResults!=0"> //testing if it is
    not empty
    <div spry:if="insSearchResults==''"> //testing if it is
    empty
    <div spry:if="insSearchResults!=''"> //testing if it is
    not empty
    <div spry:if="insSearchResults=0"> //testing if it is
    empty
    <div spry:if="insSearchResults>0"> //testing if it
    is not empty
    <div spry:if="insSearchResults=='null'"> //testing if
    it is empty
    <div spry:if="insSearchResults!='null'"> //testing if
    it is not empty

    I ended up just using one spry:if on a TR element, and the
    leaving the other TR element as is, as it would either be empty or
    filled with dynamic data. The Spry:if would only show if there wre
    no pagecounts inthe dataset. Below is a snippet of my code:
    <tr spry:if="insSearchResultsPaged.getPageCount()==0"
    align="left" >
    <td colspan="4" align="center"><br
    /><h5>No search results for that particular search. Please
    refine your search.</h5></td>
    </tr>
    <tr align="left" spry:repeat="insSearchResultsPaged"
    class="{ds_EvenOddRow}">
    <td>{insSearchResultsPaged::LastModifiedDateWithoutTime}</td>
    <td><a
    href="{Properties/Property/Value}">{insSearchResultsPaged::Title}</a></td>
    <td>{insSearchResultsPaged::Type} \
    {insSearchResultsPaged::Category} \
    {insSearchResultsPaged::Group}</a></td>
    <td><img
    src="../..{insSearchResultsPaged::IconUrl}" /></td>
    </tr>

  • How to know whether the javascript is disabled or not while loading the jsp

    Hi,
    My query is like how to know whether the javascript is disabled or not while loading the Application main JSP in Mozilla browser.
    I want some Java code or JavaScript code.

    To the point, just let JS fire a specific HTTP request inside the same session.
    This can be done in several ways. 1) Create a hidden <img> element and set the `src` attribute so that it will request a (fake) image from the server. The server just have to intercept on this specific request. 2) Fire an ajaxical request and let the server intercept on it. You can use a Filter for this which sets a token in the session scope to inform that the client has JS enabled.

  • How to find whether remote database is up or not (connected via dblink)

    Hi,
    I am using dblink to connect Biz database from Dev database.(Biz, Dev - database names)
    Running dbms job using the dblink from the Dev database to update data on Biz database...
    Problem is dbms job should run if and only if the Biz database is up for which i created the dblink...
    1) How to make sure or implement the check to find whether the Biz is database is up or not in Pl/sql or sql...
    2) How to reschedule the dbms jobs once the database is up
    pls suggest me how to find whether the database is up or not b4 running the dbms job?
    Using- Oracle 10g

    The only way to know whether the remote database is up (and whether the network between the two databases is up and whether the remote database's listener is up and whether the password configured in the database link is correct and whether the local TNS alias is correct, etc) would be to actually run a query against the remote database over the database link. In other words, the way to figure out whether the link is up is to let the job run and catch & handle exceptions when there are problems.
    By default, a job scheduled via DBMS_JOB will automatically reschedule itself if there is an unhandled exception by geometrically backing off (it waits 1 minute after the first failure, 2 minutes after the second, 4, 8, 16, 32 minutes, etc until it's marked as broken after 16 failures). You could, of course, catch appropriate exceptions and handle them in a reasonable fashion and manually reschedule jobs at intervals that make more sense for your particular job.
    Justin

  • How to know whether the phone is replaced or not?

    Dear All,
    Please help in how to know whether Iphone 5 is replaced or not? I came to know that on replacement, imei number gets changed. please make me aware.

    Nobody here can make you aware.  You need to contact Apple directly.

  • How to know whether my phone is unlocked or not

    how to know whether my iphone is unlocked or not.

    You don't know if you bought an unlocked iphone or not?
    What did you ask for?
    What does your reciept say?

  • How to find whether the cookies are enabled or not

    Hi All,
    Please suggest me, while sending the first request only how to find whether the cookies are enabled or not.
    thanks.

    you could use a servlet, write a cookie and then try to read it, if it's read then it's enabled else not.

  • How to determine whether a file doesn't exist or doesn't have enough perms

    Hello everone,
    I am stuck in determining whether a file does not exist or does not have enough permissions so that access to this file is denied?". I am using
    java.io.File.exists() or java.io.File.canRead() methods to check this but both of them just return false in both above mentioned cases.
              In the documentation however its mentioned that these method throw SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file. But then problem is to write a security manager which denies
    read access if the file does not have permissions so that exception can the thrown.
    Any suggestions or pointers will be highly appreciated.
    Thank You.
    Regards,
    Vikash Kumar

    Some platforms will let you rename or remove an open
    file.Unless those platforms support file locking, and the file has a lock on it.

  • How to Determine Whether Columns Exist in a Table

    Greetings,
    Because of customizations to our product, certain database table structures vary between different client installations. Hence, in the code, I need to determine whether two columns exist in a certain table, in order to apply some business logic.
    Please suggest a way for me to determine whether two named columns appear in a specific table. In other words, for example, I need to discover whether both columns SAL_GRADE and BONUS appear in the EMP table, or not. Only if both columns are defined, can I apply my business logic.
    Thanks,
    Avi.

    Avi,
    Like this ?
    SQL> declare
      2    l_count number;
      3  begin
      4    select count(*)
      5      into l_count
      6      from user_tab_columns
      7     where table_name = 'EMP'
      8       and column_name in ('SALGRADE','BONUS')
      9    ;
    10    if l_count = 2
    11    then
    12      dbms_output.put_line('Both columns exist, so apply business logic');
    13    else
    14      dbms_output.put_line('One or both columns are missing, so don''t apply business logic');
    15    end if;
    16  end;
    17  /
    One or both columns are missing, so don't apply business logic
    PL/SQL-procedure is geslaagd.Regards,
    Rob.

  • How to search whether a seat is available or not?

    Hi,
    I am developing a form in admin module for a call centre where there is a requirement to check whether a seat is available or not? The form contains a search window which the user enters the date in Location,catergory,From_date,to_date,time_from,time_to fields.
    For example if he enters time_from as 06:00and time_from as 14:00 .That means the seat is occupied for 8 hours but is available for the remaining 16 hours. So the search result should show this seat also in the availability list. Every seat hava a unique seat_id.
    another situation is a seat can be allocated between 22:00 and 06:00.That means it is crossing the day.That means that means in a day the seat is allocated from 00:00 - 06:00 and 22:00-23:59. How to search for this?
    The seat can be allocated for any number of hours in a day. It can be 2 hours .3 hours or 4 hours....means there is no particular time slot system.
    Can this be done using a sql query or plsql procedure?
    can anybody help me in this regard
    Thanking you,
    Deekshit

    Hi
    U can use the following query in function.
    SELECT CASE dumm
    WHEN 'X'
    THEN 'OK'
    END
    FROM (SELECT NVL (dummy, 'Y') dumm
    FROM DUAL
    WHERE TO_DATE (new_date_entered in varchar format, 'hh24:mi:ss') BETWEEN TO_DATE
    (date_from in varchar format,
    'hh24:mi:ss'
    AND TO_DATE
    (date_to in varchar format,
    'hh24:mi:ss'
    But need to b careful when the dates r changing. U can check dat by comparing time_from nd time_to values...in case of date change time_from value will be greater than time_to value(assumption==> seat can't be blocked for more than 12 hours). U can actually use the same query by reversing the conditions.. hope this will solve the problem
    Message was edited by:
    Arpit

  • How to know whether the file is opened or not

    Hi All,
    In the file handling,
    Before writing OPEN DATA SET, I want to know the file is already opened or not.
    Please help me out in this regard.
    Thanks and regards,
    Mallareddy

    Hi,
    Please try GET DATASET statement.
    Syntax:
    GET DATASET dsn.
    Extras:
    1. ... POSITION pos
    2. ... ATTRIBUTES attr
    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For details, see File Interface.
    Effect
    Used to get the properties of a file already open.
    You can use this statement without additions to determine whether the file is open.
    If the file is not open, an exception of the type CX_SY_FILE_OPEN_MODE is triggered.
    Regards,
    Ferry Lianto

  • How to find whether the tables are needed or not?

    Friends,
    Difficult situation for me......
    OS: RHEL AS 3.0
    DB: Oracle 9i R2
    I was taking table inventory.....
    i saw many tables starting with SMP..... and EVT.....Nearly 50 tables.
    some are...
    EVT_HISTORY
    EVT_DEST_PROFILE
    EVT_CARRIER_CONFIGURATION
    SMP_USER_DETAILS
    SMP_UPDATESERVICES_CALLED_
    SMP_SERVICE_ITEM_
    SMP_SERVICE_GROUP_ITEM_
    SMP_SERVICE_GROUP_DEFN_
    SMP_SERVICE_DATA_
    SMP_LONG_TEXT_
    SMP_JOB_TASK_INSTANCE_
    SMP_JOB_LIBRARY_
    SMP_JOB_INSTANCE_
    SMP_JOB_HISTORY_
    SMP_JOB_EVENTLIST_
    SMP_JOB_
    SMP_EBU_SAVED_JOB_
    SMP_EBU_ACTIVE_JOB_
    SMP_CREDENTIALS$
    SMP_BRM_TEMP_SCRIPTS_
    SMP_BRM_SAVED_JOB_
    SMP_BRM_RC_CONNECT_STRING_
    SMP_BRM_DEFAULT_CHANNEL_
    SMP_BRM_CHANNEL_DEVICE_
    SMP_BRM_ACTIVE_JOB_
    SMP_AUTO_DISCOVERY_PARMS_
    SMP_AUTO_DISCOVERY_ITEM_
    SMP_AD_PARMS_
    SMP_AD_NODES_
    SMP_AD_DISCOVERED_NODES_
    SMP_AD_ADDRESSES_
    more.........
    Nobody knows whats the table is for....
    Actually we were working with oracle 7.3 upto 2004. On 2004 we upgraded to 9iR2. May be the DBA in that time made some mistake.... i think so....thats why all these tables are still here....
    I was not in the picture during that time.
    Now my question is how can i know whether this table is necessary or not. I asked the developers here they said they are not using these tables. But my manager is afraid to delete these tables.
    now what should i do?

    Hi,
    Yet another request to use my crystal ball.
    We had one pc which is having oracle 9i enterprise manager configured(windows 2000) only to connect the db.
    This remembers me of the Gospel of St. Luke, chapter 2, where it is stated,
    'and they found the child in the manger'.
    This resulted a Jewish theologian to remark: 'The manger? Well, so that must have been their own manger'
    So what does 'the' db mean? The Linux one? Or a separate on Win2000?
    It is quite possible to manage a Linux database using OEM on Win2000, with OMS on Win2000.
    'But our server is not having enterprise manager'. Yet another riddle. Which server? There seem to be at least two.
    1 Now if I drop these tables, will I be able to connect to our database using the windows2k pc through Enterprise Manager?
    Yes, but only in standalone mode, and you can't use OEM alerts, and jobs anymore. You would be better off using Sqldeveloper, as OEM Sql worksheet is a nightmare.
    2 That is your decision.
    3
    oemctl ping oms
    will check whether you have an Oracle Management Server running.
    You already seem to have the Enterprise Manager Repository, so you must have OMS running somewhere. (Why install the repository, if you don't use it)
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • J2EE application access from Portal - P4ObjectBroker

    hey all, I want to access access a J2EE application (Web Service) from a Portal Component. The documentation at http://help.sap.com/saphelp_nw04/helpdata/en/c0/a584409db95537e10000000a1550b0/content.htm shows an example. They import the package <b>co

  • Error while launching a survey url

    Hi, I have completed the configuration settings required for generating a url link for a survey. When I test the url, I get the following error in Internet Explorer: "404 Not Found The requested resource does not exist" The landscape includes mySAP C

  • I want to upgrade my processor in my HP Pavilion dv4-2162nr Entertainment Notebook

    My computer has an intel I3 Processor and I want to know how can I make it possible to change it for an Intel Core i7 Processor Extreme, I heard that there is a version of this processor for laptops. My computer is the HP Pavilion dv4-2162nr Entertai

  • Batch user creation - what is the initial password?

    Hello experts, I'm trying to import a list of users using the batch import (User Administration -> Import) as described here: [http://help.sap.com/saphelp_nwce711/helpdata/en/48/a8a834da282883e10000000a42189c/frameset.htm] I see that the users are cr

  • Lightroom rendering into Photoshop

    I've upgraded to Lightroom 3, but I'm still using Photoshop CS3. I know that I can't upgrade Camera Raw to be able to open the new LR3 DNG's directly in Photoshop and that I need Lightroom to render them before opening.... Trouble is, I can't find th