Troubling (simple)  if  statement

I have an if statement like this:
if (session.getAttribute("userType") == "Admin")
sql ="SELECT * FROM TABLE";
else
sql = "SELECT * FROM TABLE WHERE user_type =
' " + session.getAttribute("userType") + " ' ";
//This will not work , It never generates equality .I have also tried this:
String sess = session.getAttribute("userType").toString();
//Substituting sess for session.getAttribute in query.
//Still doesnt work.
//If I change the if stmt to this it works:
if ("Admin" == "Admin")
// is there another conversion to be done when using the session.Attribute object?????
Thanks, Graham

Try this
if ((session.getAttribute("userType") != null) && (session.getAttribute("userType").equals("Admin")))
sql ="SELECT * FROM TABLE";
else
bla .. bla ....
Thanks
Sampath

Similar Messages

  • Can't make simple 'IF' statement work in MS Query!?

    I have read the existing threads on the subject but can't seem to make a simple 'IF' statement work in MS Query with a single table. I always get the following error:
    Returns error message:
    "Incorrect syntax near the keyword 'if'
    Incorrect syntax near ','.
    Statement(s) could not be prepared.
    Here's my query (simplified, but not much):
    select *
    from table t
    where t.modifieddate > if(t.active=0, date1, date2)
    Just to see if I could get AN if statement to work, I've also tried:
    SELECT t.active, if(t.active=0,2,3)
    FROM CdmsTimeSheet.dbo.Registrations t
    And
    SELECT t.active, if(t.active='0','2','3')
    FROM CdmsTimeSheet.dbo.Registrations t
    And
    SELECT t.active,
    FROM CdmsTimeSheet.dbo.Registrations t
    where datemodified>if(t.active='0',3/1/2014,1/1/2014)
    and
    SELECT t.active,
    FROM CdmsTimeSheet.dbo.Registrations t
    where datemodified>if(t.active='0',#3/1/2014#,#1/1/2014#)
    I've been using excel/ms query for many years but not in the last year or two and am wondering if this was somehow removed? I tried using decode but then get a "not built-in function" error.
    Please help! Thanks

    Not sure what kind of database you are using. In SQL Server, you should use 'Case when' Statement Or 'IIF' function instead of if.
    e.g.
    select
    top (10) BusinessEntityID,iif( BusinessEntityID=1 , 'true' , 'false') as test
    from HumanResources.Employee
    order by BusinessEntityID
    Wind Zhang
    TechNet Community Support

  • Simple Select statement in MS Access

    I am not able to get this simple select statement working in MS Access.
    "SELECT PhotoLocation from RfidData WHERE TeamID = '"+teamID ;
    It is using a variable called teamID which is a string.
    The error is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression
    Please Suggest
    Thank You...

    Let's look at your code, shall we?
    public String readPhotoLoc(String teamID)
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection(dbURL,"","");
        PreparedStatement ps = con.prepareStatement("Select PhotoLocation from RfidData ");  // There's no bind parameter here, so setString will do nothing
    ps.setString(1,teamID);
    ResultSet rs = ps.executeQuery();  // what do you do with the ResultSet?  Nothing.  //You don't return anything,  either.  I doubt that this mess even compiles.
    }Here's one suggestion for how to write it properly:
    public String readPhotoLoc(Connection connection, String teamID)
        String photoLoc = null;
         PreparedStatement ps = null;
         ResultSet rs = null;
        try
            String query = "SELECT PhotoLocation FROM RfidData WHERE TeamID = ?";
            ps = connection.prepareStatement(query);
            ps.setString(1,teamID);
            rs = ps.executeQuery();
            while (rs.next())
                photoLoc = rs.getString("PhotoLocation");
            return photoLoc;
        catch (SQLException e)
              e.printStackTrace();
               return null;
        finally
              try { if (rs != null) rs.close(); } catch (SQLException ignoreOrLogThis) {}
              try { if (ps != null) ps.close(); } catch (SQLException ignoreOrLogThis) {}
    }Make sure that the types of the columns match the Java types.
    %

  • Simple Insert Statement Not Working

    This problem is just driving me crazy. I dont know what I m
    doing wrong here. The code works fine on my localhost but giving
    problem on the live site. It is a simple insert statement like
    this:
    insert into tblSubImages(productid, title, subdescription,
    image, place)
    values(#form.productid#,'#form.title#','#form.subdescription#','#uploadedimage#',
    #form.place#)
    The error I m getting looks like this:
    Syntax error in INSERT INTO statement.
    The error occurred in
    D:\Hosting\davedhillon\superprinters\admin\addaditional.cfm: line
    11
    9 : <cfset uploadedImage = cffile.serverfile>
    10 : <cfquery name="insertadditional"
    datasource="#super.dsn#">
    11 : insert into tblSubImages(productid, title,
    subdescription, image)
    values(#form.productid#,'#form.title#','#form.subdescription#','#uploadedimage#')
    12 : </cfquery>
    13 :
    SQL insert into tblSubImages(productid, title,
    subdescription, image)
    values(1,'ewr','werw','FamilyRoomBedroom.jpg')
    DATASOURCE davedhillon_accesscf_super
    VENDORERRORCODE 3092
    You can see it is the simple insert statement which I have
    worked with so many times. Why has it started giving problem all of
    a sudden?
    Thank you

    Try copying and pasting the SQL statement produced in the
    error into your DB's query analyzer and try running it, as it might
    produce a more useful error message so you can see where the
    problem exists in the SQL statement. Also, I think I've seen that
    3092 code before and it means there is a reserved word violation so
    cf_dev2 solution will probably solve it.
    CoolJJ

  • Stored Procedures for Simple SQL statements

    Hi Guys,
    We are using Oracle 10g database and Web logic for frontend.
    The Product is previously developed in DotNet and SQL Server and now its going to develop into Java (Web Logic) and Oracle 10g database.
    Since the project is developed in SQL Server, there are lot many procedures written for simple sql queries. Now I would like to gather your suggestions / pointers on using procedures for simple select statements or Inserts from Java.
    I have gathered some list for using PL/SQL procedure for simple select queries like
    Cons
    If we use procedures for select statements there are lot many Ref Cursors opened for Simple select statements (Open cursors at huge rate)
    Simple select statements are much faster than executing them from Procedure
    Pros
    Code changes for modifying select query in PL/SQL much easier than in Java
    Your help in this regard is more valuable. Please post your points / thoughts here.
    Thanks & Regards
    Srinivas
    Edited by: Srinivas_Reddy on Dec 1, 2009 4:52 PM

    Srinivas_Reddy wrote:
    Cons
    If we use procedures for select statements there are lot many Ref Cursors opened for Simple select statements (Open cursors at huge rate)No entirely correct. All SQLs that hit the SQL engine are stored as cursors.
    On the client side, you have an interface that deals with this SQL cursor. It can be a Java class, a Delphi dataset, or a PL/SQL refcursor.
    Yes, cursors are created/opened at a huge rate by the SQL engine. But is is capable of doing that. What you need to do to facilitate that is send it SQLs that uses bind variables. This enables the SQL engine to simply re-use the existing cursor for that SQL.
    Simple select statements are much faster than executing them from ProcedureAlso not really correct. SQL performance is SQL performance. It has nothing to do with how you create the SQL on the client side and what client interface you use. The SQL engine does not care whether you use a PL/SQL ref cursor or a Java class as your client interface. That does not change the SQL engine's performance.
    Yes, this can change the performance on the client side. But that is entirely in the hands of the developer and how the developer selected to use the available client interfaces to interface with the SQL cursor in the SQL engine.
    Pros
    Code changes for modifying select query in PL/SQL much easier than in JavaThis is not a pro merely for ref cursors, but using PL/SQL as the abstraction layer for the data model implemented, and having it provide a "business function" interface to clients, instead of having the clients dealing with the complexities of the data model and SQL.
    I would seriously consider ref cursors in your environment. With PL/SQL servicing as the interface, there is a single place to tune SQL, and a single place to update SQL. It allows one to make data model changes without changing or even recompiling the client. It allows one to add new business logical and processing rules, again without having to touch the client.

  • MDX - Simple Case Statement

    For some reason I am getting an error on a Simple Case Statement
    Error (1260052) – Syntax error in input MDX query on line 2 at token ‘)’
    Case
    When IS(Time.[JAN]) THEN Time.[Feb]
    ELSE
    Missing
    End
    Any suggestions.

    Hi all,
    I have a similar problem as i'm not too sure about the correct syntax I should use
    CASE
    WHEN IS(Time.CurrentMember, Descendants[2007]) THEN .......
    ELSE
    MISSING
    END
    How do I incorporate the check for Time.CurrentMember = Descendants of 2007???
    Many thanks!

  • Can we Run a simple SQL statement from OBIEE Middle Tier node

    Hi
    i am working in OBIEE 11g environment. Database is installed on one node and Middle tier (BI services ) in other node,
    Can i use any utility to run a simple SQL statement from Middle tier ?
    Thanks
    Reddy

    Any utility means?
    We can create an ODBC connection on the BI server and run the sql.
    Mark if helps.

  • Just downloaded Numbers spreadsheet... I entered a simple "if" statement...If(c2=0,9,7) just to see how it works.... But I get an error message "Argument 1 of if expects a Boolean but found "c2=0....This if statement works fine in Excel

    Just downloaded the Apple Numbers spreadsheet app... I entered this simple 'if' statement to see how it works.... "if(c2=0,9,7)...
    I got an error message.. "Argument 1 of if statement expects a Boolean but found "c2=0".
    This if statement works fine in Excel.....What am I doing wrong ????

    Just downloaded the Apple Numbers spreadsheet app... I entered this simple 'if' statement to see how it works.... "if(c2=0,9,7)...
    I got an error message.. "Argument 1 of if statement expects a Boolean but found "c2=0".
    This if statement works fine in Excel.....What am I doing wrong ????

  • Copy records: is there a simpler sql statement

    For each record in one table "msTab" of a MS Sql Server database, I need basically to insert a new record to another one table "oraTab" in Oracle.
    I want to do this via codes to meet other requirements. I use Java with jdbc.
    It looks like a sql statement (built using codes) must look like:
    "Insert into oraTab(field1, field2, field3) values ('XXX', TO_DATE('13-NOV-92','DD-MON-YY', 322)"
    If my codes find the date data in msTab being null I thought I need to build insert statement as:
    "Insert into oraTab(field1, field3) values ('XXX', 322)", in order that Oracle will insert the default value for field2 automatically (field 2 of oraTab does not allow null).
    The logic is not as complicated if there are only 3 fields. But for a table with over a hundred fields, the codes to achieve this is not quite simple. Do I miss some simpler sql statement to do the job?
    Thanks.

    I believe Satish's suggestion was to use the DEFAULT keyword in the insert
    INSERT INTO table_name( col1, col2, col3 )
      VALUES( 1, DEFAULT, 2 );will insert the default value for col2. If you don't know which columns should take on the default value, though, I'm not sure how practical that would be.
    Were it me, I'd probably create a BEFORE INSERT trigger that replaced NULL values with appropriate default values and then just do
    INSERT INTO oracleTable( column_list )
      SELECT column_list
        FROM sqlTable@databaseLinkJustin

  • Deadlocks with simple UPDATE statement

    I have in a C# program a dictionary and in SQL Server a stored procedure with a simple UPDATE statement. I process the dictionary in parallel. For each entry in my dictionary I call this stored procedure and I am getting deadlocks.
    This is the UPDATE statement:
    ALTER PROCEDURE [dbo].[UpdateImages]
    @ICRTCode nvarchar(max),
    @ICRTImage nvarchar(max)
    AS
    BEGIN
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE() WHERE IDICRT = @ICRTCode
    END
    Can someone give me a hint as to why this would cause deadlocks? There are no other processes writing to this table. This is a table in a staging database.

    http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
    http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
    Try change the statement a little bit
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE()
    FROM
    Images
    WITH (TABLOCK) WHERE IDICRT = @ICRTCode
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Simple import statement

    Hi, I'm new to java and am having, what I believe is a simple error. Any help from a java guru would be much appriciated!
    Heres the problem.
    Say I have an EXTREMELY simple java class:
    public class printer
         public void print()
              System.out.println("Hello!");
    that lives in a file named: printer.java
    next I have another class that uses the class above (after compiling of course):
    import printer;
    public class app
         public static void main(String[] args)
              (new printer()).print();
    in a file named: app.java
    Now, both files ARE in the same directory and even my classpath variable is set for the directory that the two files live in, but every time I try and run javac on the second java file I get the following:
    C:\Compu\JAVA\test\Object\app.java:1: '.' expected
    import printer;
    1 error
    Any help would be great! And thanks!

    You don't need the import statement, only if the printer class is in another package.

  • Incompatible types in simple odbc statements

    this is my simple code
    import java.sql.*;
    public class QueryApp {
         public static void main(String a[]){
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con;
                   con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                   Statement stat=con.createStatement();
                   stat.executeQuery("Select * from Publishers");
              catch(Exception e){
                   System.out.println("Error:"+e);
    }after this when i compile i get these errors
    QueryApp.java:15: incompatible types
    found   : java.sql.Connection
    required: Connection
                con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                                                           ^
    QueryApp.java:16: cannot find symbol
    symbol  : method createStatement()
    location: class Connection
                Statement stat=con.createStatement();
                                              ^
    2 errorsCan some body help me on this error as searching on net wasn't fruitfull?

    1) You probably created a Connection class your compiler tries to use instead of java.sql.Connection. I advise to rename your class, or at least use the fully qualified classname for declaring con.
    2) The Connection class you created does not have such a method.

  • Trouble with SQL Statements

    Hello all that can help,
    i am programming in Ready to Program to connect to a VideoShop database using SQL statements.
    I am having trouble when using single and double inverted commas. eg vs.updateRentTable ("DELETE FROM RentTable WHERE CustId=);
    but instead of specifiying the CustId i want to make it a variable id so that i can delete any name i want according to their ID.
    also i am wondering if it is possible to write data from a database into a text file? is it possible to use Printwriter?
    Looking forward to your help,
    Manuking16

    Hi Manuking_16,
    Your question should be posted on a sql forum, not on a JDBC forum. Anyway. Just looking for answers, right?
    1) If your datatype is INT, you do not use either quotes " or single quotes in your SQL statement
    DELETE FROM RentTable WHERE CustId= 12345.
    To build the SQL String in JAVA just write:
    {code}String sqlStatement = "DELETE FROM RentTable WHERE CustId = " + custID; // custID will be casted to String.{code}
    2) Use preparedStatement
    {code}PreparedStatement pStm = conn.prepareStatement(�DELETE FROM RentTable WHERE CustId = ?");
    pStm.setInt(1, customerID);
    int numberOfDeletedLines = pStm.execute();3) If you want to enter the real name to do the deletion
    DELETE FROM RentTable WHERE CustId IN (select custID FROM Customer WHERE name = "joe bob johnson")
        To build the SQL String in JAVA just write: String sqlStatement = "DELETE FROM RentTable WHERE CustId IN (select custID FROM Customer WHERE name = '" + sCustomerName + "' )"; // just copy & pasteHope I got your question right.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help with a really simple SQL statement

    Hi All
    I'm relatively new to SQL and can't get my head round what I believe to be a really simple problem.
    I have a table I want to query called locations. We use locations to mean groups and regions as well as people s ofr example:
    TABLE: LOCATION
    IDENTIFIER----------NAME-----------------PART_OF
    101--------------------USER A---------------123
    123--------------------GROUP A-------------124
    etc
    What I'm trying to write is a statement that will return the 'PART_OF' as the 'NAME' rather than the ID number if the ID = 101.
    I was wondering if a nested select statement would do (select as select etc) but just can't get my head round it!
    Any ideas?
    TIA. Jake.

    Hi Jake,
    It's not clear what you are looking for. If USER A is just Part of GROUP A, a self-join will do:
    SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
                 union all
                 select 123 locid, 'GROUP A' locname, 124 part_of from dual
                 union all
                 select 124 locid, 'REGION A' locname, null part_of from dual)
    -- End of test data
    select l1.locid, l1.locname, l2.locname part_of
      from loc l1, loc l2
    where l2.locid(+) = l1.part_of
         LOCID LOCNAME  PART_OF
           101 USER A   GROUP A
           123 GROUP A  REGION A
           124 REGION A        
    3 rows selected.But if you want USER A to be part of REGION A, then you need a hierarchia lquery:
    SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
                 union all
                 select 123 locid, 'GROUP A' locname, 124 part_of from dual
                 union all
                 select 124 locid, 'REGION A' locname, null part_of from dual)
    -- End of test data
    select l1.locid, l1.locname, connect_by_root(locname) part_of
      from loc l1
    start with part_of is null
    connect by prior locid = part_of
         LOCID LOCNAME  PART_OF
           124 REGION A REGION A
           123 GROUP A  REGION A
           101 USER A   REGION A
    3 rows selected.Regards
    Peter

  • Trouble with city, state in Mysql Query

    Hello,
    I am having trouble with a query I am trying to setup.  Basically, I want the user to type in their city.  Then I want the system to ask them which city,state combo is theirs.  So if they enter "Washington" the system will return:
    Select your city/state:
    Washington, NJ
    Washington, PA
    Washington, DE
    City and state are stored as two fields in my mysql DB.  I was considering using 'select distinct' but I wasnt sure how it would work in relation to two fields.  So how would I go about making sure washington, nj only appears once (its in a database where there will be multiple washington, NJ listed).
    So anyone have any ideas or code samples they have used to do something like this?
    Thanks in advance,
    Mark

    davella wrote:
    City and state are stored as two fields in my mysql DB.  I was considering using 'select distinct' but I wasnt sure how it would work in relation to two fields.  So how would I go about making sure washington, nj only appears once (its in a database where there will be multiple washington, NJ listed).
    DISTINCT works the same way for single field or multiple fields.  It returns all distinct combinations of the values in the columns you have listed.
    SELECT  DISTINCT City, State
    FROM     Table
    WHERE  City = 'Washington'
    (Data) City, State
    Washington, NJ
    Washington, PA
    Washington, NJ
    Washington, DE
    Washington, NJ
    Washington, PA
    So for your two columns it would distinct combinations of the "City" and "State" values.  But why are there multiple "Washington, NJ" records? Are they actually different cities or duplicate records?
    (Results)
    Washington, NJ
    Washington, PA
    Washington, DE

Maybe you are looking for

  • Can not restart Microsoft SharePoint Foundation Web Application after stopping

    All, thanks for any help. I have a SP2010 instance running and am in the process of adding custom web parts, activities, and timer jobs.  As part of troubleshooting an odd problem where my code did not seem to be getting updated on deployments, I dec

  • How to use currentNode Object in jsp ???

    Hi all , I have created a component for leftNav and i have a jsp in it. The currentNode Object the jsp is returning null. Please let me know why i am getting this . Thanks in advance !!

  • Impossible to open .dtproje file after re-installing SQL Server Management Studio

    Hi all, today, after re-installing SQL Server Management Studio from a package downloaded from MS web site (SQLManagementStudio_x64_FRA.exe), I tried to open a SSIS package file via Visual Studio and I get a message stating that  this type of project

  • Multiuser Shared RPD With Presentation Server

    Hi, I recelntly set up a multiuser development environment for OBI using a network-shared RPD file (windows env). Is it possible to use it with the presentation services without copying it after every change to the OracleBI\server\Repository director

  • Can I switch from Photoshop CC to Photography CC...?

    Hi there, I currently have a 1-year subscription to Photoshop CC for $19.99/month. I saw that there is a new Photography CC Bundle that better suits my needs as a Photographer for only $9.99/month Is there any way to switch or do I need to complete m