Using toUpperCase variable in an If Statement

Hi all,
I am monitoring a user's input in my command-line program, and by converting their input to upper case, I can easily check whether they've input the correct string. However when I use the String in an If statement, it doesn't like it. Here's the simple test code I've been using:     public static void main(String[] args) {     
BufferedReader keyboardInput = new BufferedReader(new InputStreamReader(System.in));     
String priceOfPlayers = null;
try  {
     System.out.print("Price Of Players: ");
     priceOfPlayers = keyboardInput.readLine();
     priceOfPlayers = priceOfPlayers.toUpperCase();                         
     System.out.println(priceOfPlayers);          
     if (priceOfPlayers != "ORIGINAL PRICE" && priceOfPlayers != "CURRENT PRICE") {
          System.err.println("\nYou Have Entered An Invalid Option!\n");          
     } catch (Exception e) {
          e.printStackTrace();
          System.exit(1);
     }However if I type in say 'original price' or 'current price' or 'ORIGINAL PRICE', it still brings up the error message that I have written! I do not understand why it doesn't interpret the String value properly.
Any help explaining this would be superb!
thanks

Hi
String comparison should use the equals method instead of ==
if (!priceOfPlayers.equals("ORIGINAL PRICE") &&  !priceOfPlayers .equals("CURRENT RICE")) {
          System.err.println("\nYou Have Entered An Invalid Option!\n");          
     }

Similar Messages

  • How do I use a variable within a sql statement

    I am trying to use a local variable within an open SQL step but I keep getting an error.
    My sql command looks like this "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  locals.CurrentSerialNo
    If I replace the locals.CurrentSerialNo with an actual value such as below the statement works fine.
    "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  " 'ABC001' " 
    Can someone tell me how to correctly format the statement to use a variable?

    Hi,
    Thanks for the reply. I have changed the required variable to a string, but with no success. I have reattached my updated sequence file and an image of the error.
    When looking at the Data operation step I see that the sql statement is missing everything after the last quotation mark.
    Thanks again,
    Stuart
    Attachments:
    Database Test Sequence.seq ‏10 KB
    TestStand error.JPG ‏37 KB

  • How to use presentaion variable in the SQL statement

    Is there any special syntax to use a presentation variable in the SQL Statement?
    I am setting a presentation variable (Fscl_Qtr_Var)in the dashboard prompt.
    If i set the filter as ADD->VARIABLE->PRESENTATION, it shows the statement as 'Contract Request Fiscal Quarter is equal to / is in @{Fscl_Qtr_Var} '.
    And this works fine but when i convert this to SQL, it returns
    "Contract Request Date"."Contract Request Fiscal Quarter" = 'Fscl_Qtr_Var'
    And this does not work.It is not being set to the value in the prompt.
    I need to combine this condition with other conditions in the SQL Statement. Any help is appreciated. Thanks

    Try this: '@{Fscl_Qtr_Var}'

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • Using sql:variable in an insert statement

    I'm writing an insert statement for a table with an XML column.  Most of the XML is static, but I need to replace the value of an element with the value of a T-SQL variable, as shown here:
    CREATE TABLE [dbo].[OrderDetail](
    [OrderID] [int] NULL,
    [OrderDetail] [xml] NULL
    GO
    DECLARE @XMLData XML;
    DECLARE @ItemID INT;
    SET @ItemID = 1000;
    SELECT @XMLData = N'
    <OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    </OrderDetail>
    SET @XMLData.modify('insert <ItemID>[sql:variable("@ItemID")]</ItemID> into (/OrderDetail)[1]')
    INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
    VALUES (@ItemID, @XMLData);
    When I run this, it inserts "[sql:variable("@ItemID")]" instead of the value of @ItemID.  If someone could show me the proper syntax, I would really appreciate it.  Thanks.

    Yes, that worked.  Now I want to change it a little.  I also have an attribute that I need to update with the value of a variable.
    DECLARE @XMLData XML;
    DECLARE @SetID INT;
    DECLARE @SetIDStr VARCHAR(12);
    DECLARE @SetIDXML XML;
    SET @SetID = 9999;
    SET @SetIDStr = CONVERT(VARCHAR(12), @SetID);
    SET @SetIDXML = CONVERT(XML, @SetIDStr);
    SELECT @XMLData = N'
    <OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ItemID>1000</ItemID>
    <RightOperand ID="15524" Name="ItemName" Value="15524" />
    </OrderDetail>
    SET @XMLData.modify('replace value of (/OrderDetail/RightOperand/@ID)[1] with sql:variable("@SetIDXML")');
    INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
    VALUES (@SetID, @XMLData);
    SELECT * FROM [dbo].[OrderDetail];
    I'm trying to replace "ID="15524"" with the value of @SetID.  This code throws an exception:
    Msg 9342, Level 16, State 1, Line 23
    XQuery [modify()]: An XML instance is only supported as the direct source of an insert using sql:column/sql:variable.
    Thanks again for your help.

  • How do I use bind variables for the SQL statements having IN clause

    SELECT id, name FROM t
    WHERE id in (10,20,30)
    As the IN list will have 'n' number of values, I am not able to specify fixed number of bind
    variables like
    SELECT id, name FROM t
    WHERE id in (?,?,?....)

    452051 wrote:
    I am not able to specify fixed number of bind variablesYou could use collection:
    SQL> create or replace force
      2    type NumList
      3      as
      4        table of number
      5  /
    SQL> select ename from emp where deptno member of NumList(10)
      2  /
    ENAME
    CLARK
    KING
    MILLER
    SQL> select ename from emp where deptno member of NumList(10,20,30)
      2  /
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> This way you have one bind variable - collection.
    SY.

  • Using javascript variable in spry if statement

    is it possible to put a javascript variable in to the spry if
    statement to test?
    like <div spry:if="javascriptvar == {ds_RowNumber}"....
    thanks.

    Hi rogerfreak,
    When the region processes a spry:if, it simply takes the
    value of the spry:if attribute, replaces all of the data references
    in it with real values from the data set and then evals the result
    (executes the string).
    So you can do something like:
    <script>
    var ds1 = new Spry.Data.XMLDataSet("foo.xml", "/foo/bar");
    var gMode = 5;
    function GetMode()
    return gMode;
    </script>
    <div spry:region="ds1">
    <ul spry:if="gMode == 5">
    <li spry:repeat="ds1">{name}</li>
    </ul>
    <div spry:if="gMode == 12" spry:repeatchildren="ds1">
    {name}
    </div>
    </div>
    In the example above the list markup will be written out if
    gMode is 5, but if it is 12, it will write out the div markup.
    You can also call functions:
    <div spry:region="ds1">
    <ul spry:if="GetMode() == 5">
    <li spry:repeat="ds1">{name}</li>
    </ul>
    <div spry:if="GetMode()== 12"
    spry:repeatchildren="ds1">
    {name}
    </div>
    </div>
    --== Kin ==--

  • Cannot use sqlplus variable in create sequence statement

    Hello!
    I would like to create a sequence object starting with a number retrieved from a select statement:
    var max_resp_no number;
    begin
    select max(substr(resp_no,2)) into :max_resp_no from brc_mast
    where substr(resp_no,1,1)='Z';
    end;
    print max_resp_no;
    drop sequence p659_resp;
    create sequence p659_resp start with :max_resp_no;
    It tells me that :max_resp_no is an 'invalid number';
    TIA,
    habeeb

    You need to do this entirely in PL/SQL. You can either create a procedure, or use an anonymous block. The procedure version is below. Just change the CREATE to a DECLARE to get an anonymous block.
    CREATE OR REPLACE PROCEDURE new_seq IS
    max_resp_no NUMBER;
    BEGIN
    SELECT to_number(MAX(SUBSTR(resp_no,2)))
    INTO max_resp_no
    FROM brc_mast
    WHERE SUBSTR(resp_no,1,1)='Z';
    EXECUTE IMMEDIATE 'DROP SEQUENCE p659_resp';
    EXECUTE IMMEDIATE 'CREATE SEQUENCE p659_resp START WITH '|| max_resp_no;
    END;
    SQL> CREATE SEQUENCE p659_resp START WITH 1;
    Sequence created.
    SQL> SELECT p659_resp.nextval from dual;
       NEXTVAL
             1
    SQL> SELECT * FROM brc_mast;
    RESP_
    Z001
    Z002
    Z003
    Z075
    SQL> exec new_seq;
    PL/SQL procedure successfully completed.
    SQL> select p659_resp.nextval from dual;
       NEXTVAL
            75Note that the user creating this procedure will need to have CREATE SEQUENCE granted explicitly for the procedure to work. The anonymous block version should work if CREATE SEQUENCE is granted through a role.
    John

  • Using a number variable in an SQL statement

    Hi,
    I am trying to use a variable in an sql statement and I have run into problems when the variable is a number. The following line of code works if the variable is a string but not if it is a number.
    "SELECT TOP 1 UUT_STATUS FROM UNIT_UUT_RESULT WHERE UnitID =  '" + Locals.LocalUnitID + "' ORDER BY START_DATE_TIME DESC"
    Is there a difference in the use of the single and double quotes and the + sign for number variables?
    Thanks
    Stuart
    Solved!
    Go to Solution.

    Hi Stuart,
    I am assuming that the UnitID is stored as a numeric in the database? If so, the proper SQL syntax for comparing with numerics should not use a single quote (or any quotes for that matter). The quotes are used only for strings.
    So you would want to use:
    "SELECT TOP 1 UUT_STATUS FROM UNIT_UUT_RESULT WHERE UnitID =  " + Locals.LocalUnitID + " ORDER BY START_DATE_TIME DESC"
    This is really more of an SQL question universal to all languages, not just TestStand.
    Here is an excellent resource that you can consult:
    http://www.w3schools.com/sql/sql_where.asp
    Jervin Justin
    NI TestStand Product Manager

  • [php+mysql] how to use variables in a select statement?

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

  • Using Presentation variables..along with case statements..

    Hi All.
    I have a issue using presentation variable along with CASE statements. My approach is
    1) I have a dashboard prompt, which is being set as Presentation variable.
    Based on the value selected in prompt, for ex the values of prompt can be 'ABC' and 'DEF'.
    I have a calculated column, the calculation goes this way...
    The forumal is
    CASE WHEN @{Presentation Variable Name} = 'ABC' THEN xxxxxxxxxx ELSE IF @{Presentation Variable Name} = 'DEF' END. It gives error of "no table being referenced"..
    Is this is the right approach??
    Can i get the values of variable in a column formula, so that a column can have values selected in prompt?
    Can anybody pls help me here..
    Thanks in advance...

    Hi
    Thanks for the quick response..
    I agree to ur point..
    But the requirement is
    Based on the value of the prompt I need to switch the calculation in one of the formula area of one column..
    If Prompt value is ABC then one kind of calculation in Fx and If the prompt value is DEF then one kind of calculation in the same Fx..
    How can I acheive this?
    Thanks in advance..

  • Using bind variables (in & out) with dynamic sql

    I got a table that holds pl/sql code snippets to do validations on a set of data. what the code basically does is receiving a ID and returning a number of errors found.
    To execute the code I use dynamic sql with two bind variables.
    When the codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;however when I get to some more complex validations that need to do calculations or execute multiple queries, I'm running into trouble.
    I've boiled the problem down into this:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare
             some_var number;
          begin
          select 1 into some_var from dual
          where :2 = 61;
          :1 := :2;
          end;
          USING OUT counter, IN my_id;
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;this code doesn't really make any sense, but it's just to show you what the problem is. When I execute this code, I get the error
    ORA-6537 OUT bind variable bound to an IN position
    The error doesn't seem to make sense, :2 is the only IN bind variable, and it's only used in a where clause.
    As soon as I remove that where clause , the code will work again (giving me 61-61, in case you liked to know).
    Any idea whats going wrong? Am I just using the bind variables in a way you're not supposed to use them?
    I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

    Correction. With execute immediate binding is by position, but binds do not need to be repeated. So my statement above is incorrect..
    You need to bind it once only - but bind by position. And the bind must match how the bind variable is used.
    If the bind variable never assigns a value in the code, bind as IN.
    If the bind variable assigns a value in the code, bind as OUT.
    If the bind variable assigns a value and is used a variable in any other statement in the code, bind as IN OUT.
    E.g.
    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
    10                  1 into n
    11          from dual
    12          where :var1 = 61;       --// var1 is used as IN
    13 
    14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
    15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
    16  end;
    17  '
    18          using
    19                  in out id, in out cnt;  --// must reflect usage above
    20 
    21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
    22  end;
    23  /
    Procedure created.
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    PL/SQL procedure successfully completed.
    SQL>

  • How to use sql variables in jdbc send adapter??

    Hi,
    i wanna use a variable in the sql statement in the jdbc send adapter.
    i know i can key sql statement in the "Query SQL Statement" in the jdbc send adapter.but i dont know how to use variables in the sql statement.
    i mean, for example, the sql statement is "SELECT * FROM t_student WHERE READFLAG = 0", but now i wanna instead of "0"(the value of the READFLAG) using a variable.
    and if i can use a variable to replace the "0"(the value of the READFLAG above sql statement), then how can i send a value to the variable??
    request help in the regard.
    thx in advance.
    Brian

    Hi,
    Use the place holders to pass the data at runtime. Check the below structure for more details.
    Hope this helps.
    Thanks and Regards,
    Kalpesh
    <root>
      <stmt>
        <Student action="SQL_QUERY">
          <access> SELECT * FROM t_student WHERE READFLAG = '$FLAG$ </access>
          <key>
            <FLAG>0</FLAG>
          </key>
        </Student>
      </stmt>
    </root>

  • USING MULTIPLE SELECT VARIABLE IN A SQL STATEMENT

    In HTMLDB, the value of the parameter of a multiple select box is colon delimited(ie P6_Name = Smith:Jones:Burke). Is there an easy way to use this parameter in a SQL statement?
    Example
    Select *
    from names
    where
    Name=P6_Name
    Select *
    from names
    where
    Name IN ('Smith','Jones','Burke')
    Thank you

    Thank you for your response! I'm an idiot. It didn't make sense to me because your talking about a <i>multi-select</i> variable and I was thinking about a <i>select-list</i> variable. My problem is that I need to assign a list of values to one select list item.
    <br>
    For example:
    <br>
    SELECT * FROM EMPLOYEE
    WHERE EMPLOYEE_TYPE IN ( :SELECT_LIST_RETURN_VALUE );
    <br><br>
    With the select list as
    <br><br>
    Display value = All Types, Some Types, One Specific Type<br>
    Return Value = (Type1, type2, type3), (type1, type2), (type3)
    <br><br>
    I've just started in all of this so I'd imagine that I'm probably going about it wrong.

  • How to use a table name in the select statement using a variable?

    Hi Everybody,
                       I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
    Regards,
    Mallik.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

Maybe you are looking for