Test for null result set

I am trying to do a test for a null result set. Basically if the result set returns a value I want to display a table, otherwise I want to display an error message. The following code does not produce the error message. Either the test for null is incorrect, or for some reason I am not getting a null result set even when I don't enter any text into the following text boxes (this is for a login screen, these text boxes come a login screen):
<input type="text" name="username">
<input type="text" name="password">
This is the code for the action page:
<HTML>
<%@page import="java.sql.*"%>
<%
//define connection
Connection con = null;
String user1 = request.getParameter("username");
String pass1 = request.getParameter("password");
String test = "good";
try{
//get the class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//get the connection
con = DriverManager.getConnection("jdbc:odbc:errorlog", "admin", "");
//catch your exceptions!
catch(Exception e){
     out.println(e.getMessage());
%>
<title>Error Application - Logged Errors</title>
<link href="style/errorstyle.css" rel="stylesheet" type="text/css">
<BODY>
<%
//define resultset and statement
ResultSet rs=null;
Statement stmt=null;
try {
//Using the current database connection create a statement
stmt=con.createStatement();
%>
<%
String sql="SELECT* FROM tblUsers" + " WHERE Username = '"+user1+"' AND Password ='"+pass1+"'";
rs = stmt.executeQuery(sql);
%>
<% //Fetch all the records and print in table
while(rs.next()){
String user2 = rs.getString("FirstName");
String pass2 = rs.getString("LastName");
%>
<table width="100%" border="0" cellspacing="1" cellpadding="6">
<tr >
<td width="67" height="27" bgcolor="#999999"><strong><font size="- 1">First Name</font></strong>
</td>
<td width="89" bgcolor="#999999"><strong><font size="-1">Last
Name</font></strong>
</td>
</tr>
<tr>
<td>
<%out.println(user2);%>
</td>
<td><%out.println(pass2);%></td>
</table>
<%}
if (rs == null)
out.println("Incorrect Username or Password");
//close all your open resultsets, statements, and connection when you are done with them!
rs.close();
stmt.close();
con.close();
//catch all your exceptions
catch (SQLException e) {
     out.println(e.getMessage());
%>

You simply test the rs.next().
if ( rs.next() )
//spit out the rs row and
//continue processing the resultset 'til empty
else
msg = "invalid username or password
}

Similar Messages

  • [svn] 3527: + add test for message priority setting.

    Revision: 3527
    Author: [email protected]
    Date: 2008-10-08 15:49:57 -0700 (Wed, 08 Oct 2008)
    Log Message:
    + add test for message priority setting. This test sends 100 messages at priorities of different values set randomly. I store to original generated values in an array and loop over that array setting each new msg with that array indexes value. I also copy the generated value array to another array but one that is sorted
    sortedGeneratedPriorityValues = generatedPriorityValues.sort(Array.DESCENDING);
    later on we use this sorted list and compare them to the results of each message received by the consumer
    //get the message header from the message and store it.
    var result:String = e.message.headers["DSPriority"].toString();
    //assert we got the correct message for the channel being tested.
    var expected:String = sortedGeneratedPriorityValues[messageCounter].toString();
    Assert.assertEquals("Unexpected Priority: " + result, expected, result);
    Added Paths:
    blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/messagingService/priority/multip leMessagesDescendingDegreePriorityTest.mxml

  • Beginner question - testing for null string from shell script command

    I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
    I'm sure this is a simple question ... but I can't figure out how to do it. Help!

    You can use try clause for the problem:
    set _result to ""
    try
    set _result to do shell script "/blah/andblah"
    end

  • Dropdown List Value Test For Null || " "

         I wrote a pre-sign script to test a for a value in a dropdown list before allowing signature of the document. However I want to test for a value of null in addtion to one space aka " ". I added a value in the dropdown list of " " along with the choices of names so users could erase an accidental selection in this list before they were ready. However when I place the or ( || ) operator in the if statement of the script the script doesn't work. If I remove the || " " statement the script works as it is supposed to. How do I test for this value of " " along with the null test so I don't have to write another if statement?
    if (form1.Page3.Author.Reviewed.Admin.rawValue == null || " ")
    xfa.event.cancelAction = 1
    xfa.host.messageBox("You did not select your name on the dropdown list before trying sign the document .");
    else

    Your if statement is incomplete. You need to put the test in again for the other value:
    if (form1.Page3.Author.Reviewed.Admin.rawValue == null || form1.Page3.Author.Reviewed.Admin.rawValue == " ")

  • Error in testing XML query result set web service

    Hi
    I was trying to test a <b>XML query result set web service</b> in BW system with tcode wsadmin but getting error like
    <b>Cannot download WSDL from http://ibmbtsb02.megacenter.de.ibm.com:8070/sap/bw/xml/soap/queyview?sap-client=001&wsdl=1.1&mode=sap_wsdl: F:\usr\sap\W70\DVEBMGS70\j2ee\cluster\server0\apps\sap.com\com.sap.engine.services.webservices.tool\servlet_jsp\wsnavigator\root\WEB-INF\temp\ws1139464945296\wsdls\wsdlroot.wsdl (The system cannot find the path specified)</b>
    I had tried it first time few days ago and was able to test it successfully with the same configuration settings.
    Could any one of you please provide any suggestion on this?
    Thanks in advance
    Sudip

    hi
    check this links it may help u.
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/e3072e65f04445a010847aa970b68b/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/d8/3bfc3f8fc2c542e10000000a1550b0/frameset.htm
    Regards,
    Manoseelan

  • Oracle Coherence implementation for JDBC result set

    Instead of ORM, is Oracle coherence will support for accessing the data using normal JDBC calls?
    If it supports JDBC , what is the CacheStore implemetation for this?
    Can you provide me some example how to cache the JDBC ResultSet values and retrieve back from Cache?

    Hi,
    I think you mix up several concepts.
    user13266701 wrote:
    Instead of ORM, is Oracle coherence will support for accessing the data using normal JDBC calls?At the moment (up to 3.5.x), there is no way to query Coherence via JDBC out-of-the-box. There were a couple of initiatives to provide such features but they were not part of the product, only initiatives in the Incubator, but I believe they have been dropped.
    Upcoming releases may bring replacement, although I don't think it would be outright JDBC compatible, as that would imply converting an object-oriented data to result set so that you can convert it back, so it would in effect waste CPU resources.
    If it supports JDBC , what is the CacheStore implemetation for this?
    CacheStores have nothing to do with how you access the cache itself. Those are internal operations invoked by Coherence itself. Don't look for a relationship between querying the cache and doing anything with the cache store. The only relationship with them is that key-based operations on the cache may lead to operations on the cache store, but whether they do happen or not depends on the cache content, too.
    Can you provide me some example how to cache the JDBC ResultSet values and retrieve back from Cache?If I understand, that is yet a third concept. If you indeed want to cache JDBC ResultSet-s obtained from the database, then I have to disappoint you: it is not directly possible, as the ResultSet object is an abstraction over an open database cursor, and hence it keeps a database resource. Active resources cannot be cached in Coherence. You may acquire a RowSet from the JDBC driver, which would be possible to cache, however it may not be the most efficient thing to do due to possibly not optimal serialization format used by the RowSet to serialize itself.
    So if I did not answer the questions you wanted to ask, would you please explain in more detail what exactly you would like to do?
    Best regards,
    Robert

  • JSTL Core - How to test for null?

    How do I test an attribute for null using JSLT's if statement? The below code does not work (the JSTL if statement does not return true). The scriptlet however does work and displays the statement.
    - Chris
    index.jsp
    <%@ taglib uri="c.tld" prefix="c"%>
    <%@ taglib uri="fmt.tld" prefix="fmt"%>
    <%@page import="java.util.*"%>
    <%
       request.setAttribute("null", null);
    %>
    <html>
    <head>
      <title>JSTL Test Page</title>
    </head>
    <body>
    <c:if test="${null}==null">
    The value was null (JSTL)
    </c:if>
    <%
      if (request.getAttribute("null")==null) out.print("The value was null (Scriptlet)");
    %>
    </body>
    </html>
    <%out.flush();%>

    Well, I figured out. If anyone is interested, here is the code:
    <c:if test="${empty varName}">
      Its null
    </c:if>

  • Where condition to test for null

    Hi,
    I have a query where we were thinking that 2 fields will not have null values even though column allows nulls. So, wrote a query like this:
    select.......
    From table 1 left outer join table2 on (table1.name = 'I' and table2.accountnum in (table1.creditact, table1.debitact).
    Now I need to check for null if table1.creditact and table1.debitact. If both fields are null, then I have to use third column to check because out of 3 column (creditact, debitact, act) one must have account number. How can I do it.
    Thanks,
    Spunny

    I have a query where we were thinking that 2 fields [sic: columns are not fields] will not have NULL values [sic: NULL is not a value] even though column allows NULLs. So, wrote a query like this:
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. What you did post implies that your design is wrong. Did you actually have debits and credits as separate attributes in RDBMS? No, surely not! I will guess, based 30+ years of SQL, that you have a crappy design
    with too many NULLs. 
    Would you like to obey the Netiquette so we can actually help you, or you do just want a Kludge? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Trying to test for null input

    I am trying to get some input from a user using:
    String name="";       
    BufferedReader in = new BufferedReader(
        new InputStreamReader(System.in));
    name = in.readLine();Let's say the user inputs nothing other than the enter key, how can I test for this so that I can write output for it?
    In Python, one would use something like:
    if not name:
         <then do something>Thanks,
    Harlin Seritt

    Thanks for the help. When I try it with an empty
    string test, nothing happens. However, the test of
    name.length() works perfectly. Thanks!
    Harlin SerittI'm guessing you tried this, right?
    if (name == "") ...
    That's not the way to compare string values. The == operator only compares object references when comparing 2 objects. It's an extremely common mistake.

  • Custome Event for the Result Set iView

    Hi,
    does anybody know how to set up the Custom Event on the Result Set iView in order to trigger an event when a record is selected?
    I know how to do it using an event Type = EPCF + Event Name + Namespace, but this creates an extra colum on the Result Set iView with the Custom Event name on it, that has to be click in order to trigger the event. I do not want click on this column, i just want to create the event when the record is selected.
    Regards
    Diego.

    Hi Diego,
    We are also implementing similar scenario.
    We also want to open a window on the clik of any column of the result and if the result is zero we want to trigger some another iView.
    So if u have found any solution can u just let me know.
    OR else can u  just elaborate on ur current scenario using EPCF and custom event.
    Thanks in Advance.
    Regards Shruti.

  • How to avoid duplicates for an result set

    how to avoid the duplicate rows for the below query
    SELECT  to_char(grecode (titleid)) gre_code, to_char(toeflcode (titleid)) toefl_code,titleid
              FROM (SELECT DISTINCT TO_CHAR
                                       (UPPER (TRIM (get_clob_value (table_name,
                                                                     KEY
                                       ) RESULT,
                                    titleid
                               FROM mcp_specifications a JOIN mcp_title_specifications b
                                    ON a.specificationid = b.specificationid
                                    JOIN mcp_titles c ON b.titleid = c.titleid
                              WHERE b.is_parent = 'F'
                                AND UPPER (TRIM (c.university_state)) =
                                                              UPPER (TRIM ('USA'))
                                AND TO_CHAR (get_clob_value (table_name, KEY)) IS NOT NULL
                                AND UPPER (TRIM (SPECIFICATION)) IN
                                                       (UPPER (TRIM ('program'))))
             WHERE UPPER (TRIM (RESULT)) = UPPER (TRIM ('COMPUTER SCIENCE'))
          ORDER BY RESULT ASC;the output of the query would be
    gre_code    toefl_code   titleid
    402             78             5518
    402             78             5519
    402             78             5520
    402             78             5521the output should be
    402 78 any titleid

    Some simplified code:
    SELECT grecode(titleid) gre_code,
           toeflcode(titleid) toefl_code,
           min(titleid) titleid
    FROM   (SELECT DISTINCT TO_CHAR(UPPER(TRIM(get_clob_value(table_name,KEY)))) RESULT,
                   titleid
            FROM   mcp_specifications a
                   JOIN mcp_title_specifications b
                        ON a.specificationid = b.specificationid
                   JOIN mcp_titles c
                        ON b.titleid = c.titleid
            WHERE  b.is_parent = 'F'
            AND    UPPER(TRIM(c.university_state)) = 'USA'
            AND    TO_CHAR (get_clob_value (table_name, KEY)) IS NOT NULL
            AND    UPPER(TRIM(SPECIFICATION)) = 'PROGRAM')
    WHERE  UPPER(TRIM(RESULT)) = 'COMPUTER SCIENCE'
    GROUP BY grecode(titleid),
             toeflcode(titleid)Please note that applying functions like UPPER and TRIM on a string literal can and should be avoided.
    For example:
    UPPER(TRIM('USA')) = 'USA'Why force the database to do both an UPPER and a TRIM on something that can just be represented in uppercase with no surrounding spaces? It's a waste of time.

  • Query of queries testing for null or empty dates

    I'm having problems with this query (within a function). The
    last condition in the where clause needs to check for an empty or
    null date and then check against the current date (which is fine),
    im aware that the syntax is wrong but wondered if someone could
    correct it for me to get it working.
    <cfquery name="filterQuery" dbtype="query"
    maxrows="#arguments.top#">
    select * from getAllSaved
    where
    workFlowStatusId = <cfqueryparam
    cfsqltype="CF_SQL_INTEGER"
    value="#application.const.WORKFLOW_LIVE#" />
    and
    dateArchive > <cfqueryparam cfsqltype="CF_SQL_DATE"
    value="#now()#" />
    and
    dateLive <= <cfqueryparam cfsqltype="CF_SQL_DATE"
    value="#now()#" />
    and
    (dateExpiry is null or dateExpiry = '') or dateExpiry >
    <cfqueryparam cfsqltype="CF_SQL_DATE" value="#now()#" />
    </cfquery>

    I feel stupid, although i'd put a fiver on having tried that!
    thanks

  • Stored procedure call returns null result set when using temp table in sp!

    Here's a really odd problem...
    SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
    cStmt = connection.prepareCall("{call sp_Test(?)}");
    cStmt.setInt(1, 44);
    cStmt.execute();
    rs = cStmt.getResultSet();When the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      SELECT node_id FROM tbl_NavTree
    END
    GOthe query works and I get all node_id back in rs
    BUT when the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      CREATE TABLE #Descendants(
        descendant_id INT
      SELECT node_id FROM tbl_NavTree
      DROP TABLE #Descendants
    END
    GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
    Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
    Must be JDBC .. what can it be!??

    DROP TABLE #DescendantsMS SQL Server - right?
    Then don't drop the table.
    From the MS docs for "create table"
    Local temporary tables are visible only in the current session;
    A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table.

  • How can i display units only for the result set

    hi
    i do not want to display units (example: $ or %) for my key figure columns but i want to display units to the result.
    how can i do that

    Hi Surya,
    I don't think it is possible to have both non-unit and unit in the same kf.
    One potential workaround to do this is to create a calculated key figure/ formula that use the NODIM function for single values. Example: NODIM(0AMOUNT). Then, create a calculated key figure/formula that computes overall result on the same kf and supresses individual values but does not use NODIM....perhaps this can help you work out a solution.
    Hope this helps.
    Regards,
    Petter
    Message was edited by: M Petter

  • Can you really use Display String formula to test for NULL

    I am trying to manipulate the Display String of a field throught the Format Editor.  If a field is null, it should display "N/A", or "No data given", or anything else appropriate I might choose.
    I can't get this feature to work and I'm wondering if there's a bug here.  I'm using the following formula:
    if (isnull() or    trim() = "")
    then "N/A"
        else
    Am I doing something wrong or is there a better way to do this?

    Hi Adriane
    The other way to display "N/A", or "No data given" if a field is null is using a formula with if -else statement as follows:
    whileprinting records;
    if (isnull() or trim () =" ")
    then "N/A"
    else
    Please let me know if this helps.
    Thanks
    Poonam Thorat

Maybe you are looking for

  • Deleting Photos from my hard drive

    I have to create some more room on my hard Drive I have backed it up. I have over 10,000 pictures in iphoto and I have deleted 8000 from my originals file however the thumbnails in the photo albums still exist? how do I get rid of them. When I back u

  • Report painter report with two header rows

    Experts, I have managed the variable values in report painter but in display output i am unable to recognize the value displayed for march / April is actual or planned Please find attached screen shot for the same... Is there any way to have both the

  • Is there a way to turn back on the zooming effect without the paralex effect in IOS 7.0.3?

    Is there a way to turn back on the zooming effect without the paralex effect in IOS 7.0.3?

  • Catch and global vars

    look at this code: package OkudaFont; import java.awt.*; import java.io.FileNotFoundException; import java.io.FileInputStream; import java.io.InputStream; import javax.swing.*; import java.awt.event.*; public class OkudaFont      Font font = null; //

  • Slicing Fireworks image to create a website?

    I have created a large image and will like to slice it to make a website. How can I best do this?? I tried to slice it but the text on the image did not appear well on the internet browser. I now want to remove the text from the original image, slice