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.

Similar Messages

  • 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
    }

  • IPhone SDK - test for sound input availability?

    Should one try to determine if the device has a microphone available before calling AudioQueueNewInput and AudioQueueStart? I didn't see any mention of this requirement in the Audio Queue Services Programming Guide. (But in ancient MacOS history, one used to at least check the gestaltSoundAttr for the gestaltPlayAndRecord flags before trying to use the Sound Manager...)
    I have some audio queue input code which seems to work on the SDK simulator; what will happen if someone tries to run this code on an iPod Touch, which doesn't have a mic (AFAIK)? And if someone attaches a mic to the iPod dock connector, can this be detected and used?

    Good Question. I did just that. It seems that the iPod touch thinks that the input device is present and the call to AudioQueueStart returns 0. Good or bad, I don't know. I assume that this function should trigger the callback function to the delegate, but it only works in the simulator. This can be seen with the Speak Here app that is posted for examples. The debugger console shows a call to updateUserInterfaceOnAudioQueueStateChange when recording begins and when recording ends. On the iPod touch the call to the delegate is only done when recording stops.
    I would also like to know how to test for an input device.

  • 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 == " ")

  • 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

  • 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

  • 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

  • Unpivot task is generating rows for null inputs

    So I have a C# application (VS 2012 with .NET4.5) that builds SSIS (SQL2012) packages programatically.  the packages can be opened in the designer and they run fine.  However, there is one case that is giving me a problem.  I have an
    OleDb source connected to a table in SQL server.  I am using the unpivot task to convert columns in a sparse matrix to an Entity Attribute Value model.  So basically, the primary key value of the source table is a pass-through value in the unpivot
    task, each column is mapped to the destination column, and the attribute id is hard coded as the pivot key.  Like i said this works great EXCEPT i came across one column and a table that was null for all the rows in the table.  when I run the package,
    it fails with:
    OnError,SERVERNAME,DOMAIN\user,{94E83A3B-5386-4712-BEDC-11E35341675F},{94E83A3B-5386-4712-BEDC-11E35341675F},{3187347C-8D44-4D51-8FDB-B5C4159A58B0},9/14/2012 9:48:02 AM,9/14/2012 9:48:02 AM,-1071607780,0x,There was an error with OLE DB Destination.Inputs[OLE
    DB Destination Input].Columns[AttributeId] on OLE DB Destination.Inputs[OLE DB Destination Input]. The column status returned was: "The value violated the integrity constraints for the column."
    So I set up a data viewer on the data flow and found that the unpivot component was generating rows for every null value. not only that, but the values for the key column and the attribute id (which was hard coded) were also null for all the rows
    sent from the unpivot to the ole db destination.  I manually created a package with an unpivot for just the column in question and got the same result.  then I inserted a value for every row in the table and the same package runs fine.
    can someone offer any help or advice on what might be causing this?

    its just two columns of data that are concerned.  ten character numeric strings in the one and null in the other.  the pivot key is hard coded in the unpivot component configuration screen.  see the output of the data viewer below. How do
    I get Microsoft involved with this?
    2013399057 NULL
    2013399488 NULL
    2013399770 NULL
    2013402244 NULL
    2013402440 NULL
    2013404066 NULL
    2013404070 NULL
    2013404203 NULL
    2013404206 NULL
    2013404401 NULL
    2013404589 NULL
    2013404705 NULL
    2013404738 NULL
    2013404768 NULL
    2013404784 NULL
    2013404813 NULL

  • 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

  • Searching for NULL with a FindPanel?

    Can I search for null values in my dataset using the FindPanel
    InfoBus control?
    From what I can gather, it actually puts together a primitive
    kind of where clause that I can trick to a certain extent (eg
    entering a criteria of "ANY (value, value,...)" to simulate an IN
    clause - because it will prepend the criteria with an equals
    sign), BUT I can't get it to find NULL values, which requires the
    IS NULL operator.
    Lachlan
    null

    We've found a workaround, which is ugly, but works.
    In the FindPanel, to successfully search for nulls, you can enter
    a combination of two conditions joined with an OR operator. For
    example, to search for members in the ACME_MEMBERS table with a
    null MID_INITIAL, I could enter the condition:
    = 'XXX' OR MID_INITIAL is null
    and then the WHERE clause will be:
    WHERE MID_INITIAL = 'XXX' OR MID_INITIAL is null
    which will find the rows I'm looking for.
    BUT, this is REALLY ugly, and there should be a better way.
    If anyone knows of a better way, please let me know.
    Lachlan
    Lachlan Williams (guest) wrote:
    : I am assuming that the FindPanel will call the associated
    : DataItem's setQueryCondition and then actually execute the
    query
    : for me, all happening when I press the Find button.
    : I can't see where in this paradigm there is an opportunity to
    : alter the where clause.
    : So to rephrase my original question: how can I explicitly test
    : for null values using the existing functionality of the
    FindPanel
    : control? (ie how do I get the IS NULL operator into the where
    : clause?).
    : Thanks,
    : Lachlan
    : JDeveloper Team (guest) wrote:
    : : Hi
    : : The FindPanel relies on RowSetInfo 's setQueryCondition. you
    : can
    : : try to directly use this method to set the query condition.
    : : regards
    : : Lachlan Williams (guest) wrote:
    : : : Can I search for null values in my dataset using the
    : FindPanel
    : : : InfoBus control?
    : : : From what I can gather, it actually puts together a
    primitive
    : : : kind of where clause that I can trick to a certain extent
    (eg
    : : : entering a criteria of "ANY (value, value,...)" to simulate
    : an
    : : IN
    : : : clause - because it will prepend the criteria with an
    equals
    : : : sign), BUT I can't get it to find NULL values, which
    requires
    : : the
    : : : IS NULL operator.
    : : : Lachlan
    null

  • Browser application test for Firefox with JLP

    How much different if Firefox (en-US) is configured to added-on the Japanese Language pack (JLP)?
    I'm planning on the browser test for Firefox on the following condition:
    Operating System / Windows 7 (Japanese)
    Browser / Firefox Setup 10.0.2, 11.0, 12.0 each
    *For each Firefox version, to add-on the JLP @ ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/10.0.2/win32/xpi/ja.xpi (in case of 10.0.2)
    Testing covers not just what the layout looks good, but also to check if the encoding through database functions well.
    I'd really appreceate if someone would tell me the impact on the add-on JLP to Firefox (en-US).

    cor-el, thanks for your quick answer! It makes it clear that JLP only affects strings settings and shortcut keys (keybord stuffs).
    I'm trying to test for several browsers from the viewpoint of the followings;
    1. JavaScript
    2. VMware Remote Console (VMRC) plug-in
    3. HTML5 File Reader API
    It seems that nothing can be differenct to check if these works, when Firefox addons the JLP xpi file.
    I'd really appreciate ii if you give me any extra comments aobut the test on this conditions.

  • Testing for IS NOT NULL with left join tables

    Dear Experts,
    The query is showing the NULL rows in the query below....
    Any ideas, advice please? tx, sandra
    This is the sql inspector:
    SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE
    , O100404.NAME, O100321.PERSON_UID, O100404.PERSON_UID, O100404.VISA_TYPE
    FROM ODSMGR.PERSON O100321
    , ODSMGR.VISA O100404
    WHERE ( ( O100321.PERSON_UID = O100404.PERSON_UID(+) ) ) AND ( O100404.VISA_TYPE(+) IS NOT NULL )

    Hi Everyone,
    I am understanding alot of what Michael and Rod wrote.... I am just puzzled over the following:
    the query below is left joining the STUDENT table to
    HOLD table.
    The HOLD table - contains rows for students who have holds on their record.
    a student can have more than one hold (health, HIPAA, basic life saving course)
    BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
    Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
    1 to many relationship.
    Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
    me having to code IS NOT NULL twice....
    Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
    created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
    the IS NOT NULL condition.
    I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
    and how they should create a query. I need to come up with rules.
    If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
    Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
    thx sooo much, Sandra
    SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
    FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
    WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
    GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
    HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
    ORDER BY O100384.NAME ASC

  • I'm trying to record in Adobe Audition and it keeps saying my the sample rates for my input and output devices do not match.  How do I correct this?

    I'm trying to record in Audition and it keeps saying my sample rates for the input and output devices don't match.  How do I fix this?

    I finally have communication between the ISA One and Audition. I moved the optic cable to another SPDIF on the computer and from the SPDIF to ADAT on the ISA One and it finally agreed that the communication was at the same clock speed. The audio was not intelligible so I moved the optic cable back to the original configuration and I can record voice that is clean.          

  • Check for null and empty - Arraylist

    Hello all,
    Can anyone tell me the best procedure to check for null and empty for an arraylist in a jsp using JSTL. I'm trying something like this;
    <c:if test="${!empty sampleList}">
    </c:if>
    Help is greatly appreciated.
    Thanks,
    Greeshma...

    A null check might not be you best option.  If your requirement is you must have both the date and time component supplied in order to populate EventDate, then I would use a Script Functoid that takes data and time as parameters.
    In the C# method, first check if either is an empty string, if so return an empty string.
    If not, TryParse the data, if successful, return a valid data string for EventDate.  If not, error or return empty string, whichever satsifies the requirement.

Maybe you are looking for

  • How can I convert files in Aperture to jpegs and keep the file large

    I want to upload files into istock photo and they must be as big as possible but in jpg format. I end up exporting tiny little things going from 8mb to 300kb. How can I do it? I even tried going into CS3 but that only allowed me to convert to tif. I

  • Is there any table or report that available in SAP for any PR/STR

    HI All, Is there any table or report that available in SAP for any PR/STR that are remain opened after S/O canceled. Please advice at the earliest. Thanks Chandru

  • 5200CD won't start/do much of anything

    We have 5200CD that won't start up. My father (whose beloved computer it is now) had noticed that he was having difficulty getting it to start - sometimes, he would have to press the start up key two or three times - so he left it running for a coupl

  • Is it possible to use a WVC80N on Virgin Mobiles Mifi2000 Hotspot?

    Anyone know if it is possible to use a WVC80N on Virgin Mobiles Mifi2000 Hotspot?  I live out in the country and the only network connection we have is via the Mifi2000 3G portable Wifi Hotspot. So far I have not had any luck setting this up, mainly

  • Creating sequence in Pointbase db

    Hi, i am a student trying to develop a database using Pointbase by Sun Microsystems. Does anyone know the SQL coding for creating a sequence in pointbase because the SQL coding is slightly different compared to Oracle. In Oracle the normal coding wou