Trying to compare 2 strings using sql...should be an easy one

I have a String variable named 'code' that = "xyz". I have "xyz" in my DB under the userCodes column. And I have the following in my Java code:
String query = "SELECT userCodes FROM accounts";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
thisCode = rs.getString("userCodes");
if (thisCode == code) { System.out.println("ITS THE SAME CODE"); }The problem is that Java is not recognizing thisCode as being equal to code, when they clearly are equal. Could someone please tell me why the two strings are not equal?
Thanks.

Since strings are objects you have to use equals metho to test the equality of the strings.
Or in sql you can do this by adding a where clause
PreparedStatement ps = connection.prepareStatement("SELECT userCode FROM accounts WHERE userCode=?");
ps.setString(1,code);
ResultSet rs = ps.executeQuery();
...

Similar Messages

  • Compare Encrypted String Using SQL

    I have some data encrypted in SQL.
    I want to use the LIKE command in SQL to compare a submitted form value to an encrypted value in the table.
    How can I do this?
    <cfquery>
    SELECT *
    FROM table
    WHERE decrypt(name,key) = '#form.name#'
    </cfquery>
    Of course the decrpyt does not work in the example above as it gives an error. But how can I achieve the results without error?
    Thanks.
    Chuck

    Making some headway here.
    Here is what I have so far.
    <cfquery name="cust" datasource="#DSN#" username="#USER#" password="#PASS#">
    SELECT *
    FROM customer
    </cfquery>
    <CFLOOP query="cust">
    <CFSET temp = QuerySetCell(cust,"decust_co","#Decrypt(cust.cust_co,variable.ekey)#",#cust.currentrow#)>
    <CFSET temp = QuerySetCell(cust,"decust_last","#Decrypt(cust.cust_last,variable.ekey)#",#cust.currentro w#)>
    <CFSET temp = QuerySetCell(cust,"decust_first","#Decrypt(cust.cust_first,variable.ekey)#",#cust.current row#)>
    </CFLOOP>
    [Didn't think you would have to loop the QuerySetCell's, but you do
    <cfquery dbtype="query" name="decust">
    SELECT *
    FROM cust
    WHERE custid > 0
    AND (decust_co LIKE '%#search#%'
    OR decust_last LIKE '%#search#%'
    OR decust_first LIKE '%#search#%'
    OR acct_no LIKE '%#search#%')
    ORDER BY decust_co
    </cfquery>
    OK...the part that is not working is my wildcard seach values. When I send a search variable of a single letter - C, M, H, etc...it will bring back results. If I send a NULL search variable - it will bring back all results...when I send a search variable with more than two characters - zero results. I am using two characters like "Ch" and one of the values is "Chuck". It should bring back a result. This query worked fine, prior to encrypting this data. I have verified the data in the QuerySetCell variables above are populating and decrypting correctly when I dumped the query.
    Any idea?

  • How do count how many 'A' s in this string using sql stmt?

    hi all,
    i have a string like 'AAAAARAMAAAAKRISHNAAAA'.
    in this ,i want to find out how many 'A's .
    how do find out this using select stmt.

    (length(s) - nvl(length(replace(s, 'A')), 0)) / length('A')but consider (by modifying the question slightly to "how do count how many 'AA' s in this string using sql stmt? ")
    SQL>  select (length('AAAAARAMAAAAKRISHNAAAA') - nvl(length(replace('AAAAARAMAAAAKRISHNAAAA', 'AA')), 0)) / length('AA') x from dual
             X
             6
    1 row selected.couldn't I argue that the result should be 10 as e.g. in
    SQL>  select * from xmltable('let $str := "AAAAARAMAAAAKRISHNAAAA"
                            let $search := "AA"
                            for $i in 1 to string-length($str)
                              where substring($str, $i, string-length($search)) = $search
                              return substring($str, $i, string-length($search))' columns x varchar2(10) path '.')
    X        
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    10 rows selected.Matter of definition I suppose .... ;)
    btw. regexp_count also yields 6:
    SQL>  select regexp_count('AAAAARAMAAAAKRISHNAAAA', 'AA') x from dual
             X
             6
    1 row selected.

  • Need Help in Splitting a String Using SQL QUERY

    Hi,
    I need help in splitting a string using a SQL Query:
    String IS:
    AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
    Sample Output should look like:
    SNO       STRING
    1            AFTER PAINT
    2            ACOUSTICAL
    3            1
    4            
    5            9" MEMBRAIN
    {code}
    FYI i am using Oracle 9.2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    There's this as well:
    with x as ( --generating sample data:
               select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
               select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
    select str,
           row_number() over (partition by str order by rownum) s_no,
           cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
    from x,
         table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
    STR                                                S_NO RES                                                                                                
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 1 AFTER PAINT                                                                                        
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 2 ACOUSTICAL                                                                                         
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 3 1                                                                                                  
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 4                                                                                                    
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 5 9" MEMBRAIN                                                                                        
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          1 BEFORE PAINT                                                                                       
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          2 ELECTRIC                                                                                           
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          3 2                                                                                                  
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          4                                                                                                    
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          5 45 caliber MEMBRAIN      
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Using SQL Loader in more than one table

    Hi all,
    I have a new question for those who have used SQL Loader. I
    have never used it and I just know that I need a control file to
    tell SQL Loader what is my flat file layout and what table the
    information goes to. My problem is: my flat file has information
    that goes to two tables in my schema. Those files are very big
    (aprox 280Mb) and I would like to read them just once. Can I do
    this with SQL Loader?
    Other question, is that the fastest way to import data from
    flat files becouse I am using PERL and it takes aprox. 9 hours
    to import 10 of those files. I could use UTL_FILE to read it but
    I heard that SQL Loader was better.
    Thanks for your cooperation
    (Robocop)
    Marcelo Lopes
    Rio de Janeiro - Brazil

    SQL*Loader is the fastest way to load, particularly in direct parallel mode, and can certainly load to multiple tables.
    >
    My advice would be to have a look at the examples given in the Oracle Utilities guide, there is one for loading to multiple
    tables, which I have pasted below.
    >
    -- Loads EMP records from first 23 characters
    -- Creates and loads PROJ records for each PROJNO listed
    -- for each employee
    LOAD DATA
    INFILE &#8217;ulcase5.dat&#8217;
    BADFILE &#8217;ulcase5.bad&#8217;
    DISCARDFILE &#8217;ulcase5.dsc&#8217;
    REPLACE
    INTO TABLE emp
    (empno POSITION(1:4) INTEGER EXTERNAL,
    ename POSITION(6:15) CHAR,
    deptno POSITION(17:18) CHAR,
    mgr POSITION(20:23) INTEGER EXTERNAL)
    INTO TABLE proj
    -- PROJ has two columns, both not null: EMPNO and PROJNO
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(25:27) INTEGER EXTERNAL) -- 1st proj
    INTO TABLE proj
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(29:31 INTEGER EXTERNAL) -- 2nd proj
    INTO TABLE proj
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(33:35) INTEGER EXTERNAL) -- 3rd proj
    see the documentation for a complete explanation of the configuration.
    Thanks, I will read it.

  • This should be an easy one for you experts ;-)

    Just took my vintage 2009 Macbook pro that was having trouble running Lion back down to Snow Leopard. (formatted drive and reloaded SL) How do I get iPhoto, Garage Band, Imovie etc.... in other words the apps that came installed on my 2009 machine when I bought it. They aren't part of the SL install.
    No need to be concerned about my user data/settings/other apps etc... I migrated them over to a new Macbook pro I just purchased using a Time Machine backup. (worked wonderfully) but as I'm sure you know moving anything from a Lion TM backup to a SL machine isn't possible. I've heard there are ways but it's complicated and well all I really want is my 2009 machine to be like it was new and I'll I need for that is what I believe is the iLife stuff (again iPhoto, Garageband, iMovie etc...)

    Thanks for the quick reply wjosten! I didn't get any disks with my computer. I bought it new from the online apple store.. I still have the original box it came in, user guide etc...it came loaded with Leopard but no disks. I had the SL disk as I purchased it to upgrade ( I know I could have downloaded it for free but I wanted a disk for the exact reason as for how I just used it to reinstall SL in case I needed to someday).  In fact, I just bought a 2012 MacBook Pro, picked it up at my local Apple store and it did not come with any disks, same as before, it came with power cord, user guide, cleaning cloth, but no disks. I can understand that apple saves money, time, resources and environmental material by not including disks, but they should make it easy to download these things when you are in trouble and not charge even a small fee. I paid for these apps and merely want to reinstall them on the same machine they orignally came with.

  • Insert String Using SQL Query

    Hi, EveryOne,
    I tried to insert(update) a string data type using Fixed SQL Query as, for a example:
    insert into Masters(MasterName) values([Param.1])
    In html form I enter a value in field and press button to call the function. But if enter in the field a String value - nothing inserted in table but if I enter Number - everything works fine. I tried to use commas but the effect is the same.
    Thnks,
    Serj

    Hello Sergey,
    Ryan's sql statement is right. The ' sign is used to mark the [Param.1] as a string.
    The sql statement (connection) is language independent, but you have to make sure that you mark up strings and timestamps in the correct way.
    In your first statement
         Masters(MasterName) values([Param.1])
    xMII will replace [Param.1] with the value you type in("yourvalue"). For strings("yourvalue") it will look like this
         Masters(MasterName) values(yourvalue)
    this should bring back a sql error. You can try it in another sql client.
    Hope this help as an explanation.
    Regards,
    Martin

  • Make a large string using sql

    Ok all I want to do is generate a string of length X.
    so to generate a 1000 character string of 'X's I'm doing the following:
    select replace ('X','Y',1000) from dualThis is Just giving me X.
    What am I doing wrong.

    Use LPAD/RPAD:
    select lpad('X', 1000, 'Y')
    ,      length(lpad('X', 1000, 'Y'))
    from dual;http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions082.htm#SQLRF00663
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions140.htm#SQLRF06103

  • How to split a string using sql

    Hi All,
    I've to write a query where I need to split a string, how this can be done? So let's say a column has value as 1,2,3,4,5 and I want to split this string and output it as:
    1
    2
    3
    4
    5
    Please advise.

    Lots of articles:
    Snap this user defined function too:
    CREATE FUNCTION [dbo].[ufn_SplitString_Separator](@InputStr VARCHAR(MAX), @Separator VARCHAR(1))
    RETURNS @tmpTable TABLE (OutputStr VARCHAR(MAX))
    AS BEGIN
    DECLARE @TmpPOS integer
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    WHILE @TmpPos > 0 BEGIN
    IF @TmpPos > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(SUBSTRING(@InputStr,1,@TmpPos-1))))
    SET @InputStr = SUBSTRING(@InputStr, @TmpPOS + 1, LEN(@InputStr) - @TmpPos)
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    END ELSE BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    SET @TmpPos = 0
    END
    END
    IF LEN(@InputStr) > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    END
    RETURN
    END
    GO
    And you can use like this:
    SELECT * FROM DBO.[ufn_SplitString_Separator]('1,2,3,4,5',',')
    "If there's nothing wrong with me, maybe there's something wrong with the universe!"

  • Splitting string using SQL

    Hi all,
    I have a column(address) which I have to split into 4 parts. This may contain 1 or more lines(separated by new line). How to split this.
    create table t(address varchar2(50));
    insert into t values('first'||chr(10)||chr(13)||'second');
    Antony Paul.

    Hi,
    My first guess would be a simple substr with an instr.
    Find the position of the chr(10) chr(13) combination and do a substring. It will not be very fast, but it will work.
    An alternitive is using a function to return the values you need.
    Jeroen

  • JSPs reference to JPEGs .. this should be an easy one!

    Hi,
    We are moving our 6.20 java apps to NW04S J2EE apps. So, we have created EJB, Web and EAR projects for this.
    In NWDS, we have used Import File to bring in all of our JSPs. NWDS stores them under the webContent folder in the Web project. Each JSP refers to /DCT/images/<filename>.jpg.
    We have also used Import File to bring in the 6.20 images folder. In the project it is under /webContent/DCT/images.
    When we preview the JSPs, the images do not show up unless we change the reference in the JSP to DCT/images<filename.jpg (no leading slash). Since there are so many JSPs we do not want to change the references in the JSPs.
    Two issues we found:
    1. We can only create a folder structure under webContent. It seemed to us that we would need to create /DCT/images at the project root.
    2. In preview mode, when we right click -> propeties on the missing jpgs it says the jpg should be at c:\DCT\images. It is completly ignoring the file structure of our project.
    Any clues to this mystery would be greatly appreciated.
    Cheers ... Bart

    "garywpaul" <[email protected]> wrote in
    message
    news:f9f35h$n0t$[email protected]..
    > Well, I tried it with a jpg and it just opened. Is this
    the same thing
    > that
    > will happen with PDF files?
    If you link directly to a PDF, and the user has Adobe Acrobat
    installed
    (which the vast majority do), it will open within the browser
    in Acrobat
    Reader. The user can then choose to click the Save button and
    save it to
    whatever location he wants.
    This should be fine for a restaurant menu. This was, the user
    can look at
    the menu online to his heart's content, and only save it if
    he really wants
    to have a local copy. (You might include, near the link, a
    very brief
    one-line instruction.)
    > I would like for the dialog box to open (Save file
    > as) and the file be saved on the visitors computer.
    If that's what you really want, you can zip the PDF into a
    zip file, and
    link to the zip file. That way, the user will get the dialog
    box that you
    want.
    Patty Ayers | Adobe Community Expert
    www.WebDevBiz.com
    Free Articles on the Business of Web Development
    Web Design Contract, Estimate Request Form, Estimate
    Worksheet

  • Regular expression question (should be an easy one...)

    i'm using java to build a parser. im getting an expression, which i split on a white-space.
    how can i build a regular-expression that will enable me to split only on unquoted space? example:
    for the expression:
    (X=33 AND Y=44) OR (Z="hello world" AND T=2)
    I will get the following values split:
    (X=33
    AND
    Y=34)
    OR
    (Z="hello world"
    AND
    T=2)
    and not:
    (Z="
    hello
    world"
    thank you very much!

    Instead of splitting on whitespace to get a list of tokens, use Matcher.find() to match the tokens themselves: import java.util.*;
    import java.util.regex.*;
    public class Test
      public static void main(String[] args) throws Exception
        String str = "(X=33 AND Y=44) OR (Z=\"hello world\" AND T=2)";
        List<String> tokens = new ArrayList<String>();
        Matcher m = Pattern.compile("[^\\s\"]+(?:\".*?\")?").matcher(str);
        while (m.find())
          tokens.add(m.group());
        System.out.println(tokens);
    }{code} The regex I used is based on the assumptions that there will be at most one run of quoted text per token, that it will always appear in the right hand side of an expression, and that the closing quote will always mark the end of the token.  If the rules are more complicated (as sabre150 suggested), a more complicated regex will be needed.  You might be better off doing the parsing the old-fashioned way, with out regexes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • New to MAC  -help with previous systems folder -this should be an easy one!

    My PowerBook G4 (running Leopard) recently crashed due to some corrupt files, per the Genius Bar. I got it up and running with the Leopard upgrade disc as they recommended. Everything went well and on the HD it created a "Previous Systems" folder and everything is in there... (old applications, documents, etc. ... Now what do I do?
    Do I just run the applications (iWork, MS Office, Adobe products, etc.) from that "Previous Systems" folder or should I drag and drop them to the new applications folder, or is it better to delete and reinstall all the programs again? And if I have already opened some of the applications from the Previous Systems" folder will this prevent me from moving them.
    I just want to clean up my laptop and keep it simple... What is the safe and easy thing to do?
    Thanks for all the help... this site is what influenced me to switch from PC to MAC !
    John

    Start with the description in http://docs.info.apple.com/article.html?artnum=301270
    Once you sort that out, see:
    Switching from Windows to Mac OS X,
    Basic Tutorials on using a Mac,
    MacFixIt Tutorials, and
    MacTips Learning Centre.
    Additionally, *Texas Mac Man* recommends:
    Quick Assist.
    Welcome to the Switch To A Mac Guides, and
    A guide for switching to a Mac.

  • Now this should be an easy one !!     IPOD Software needs reinstalling...

    Hello
    I have an IPOD Nano, and it was installed on my PC, an
    IBM 266 Laptop, with Windows XP Pro. Unfortunately a problem has occurred.. I now find on clicking the itunes icon that "itunes cannot run because some of its required files are missing. Please reinstall itunes".
    I have tried to reinstall from the Control Panel, and have done what I thought was a complete reinstall, but still the same message comes back. I suspect that Quicktime is not properly installed. The only option seems to me to
    manually delete every ipod file, until the computer is clear, then reinstall. The only problem is, I don't want to lose the music files that are already on the Nano.
    Can anyone advise, please ?
      Windows XP  

    > Removing iTunes will not remove anything from the
    iPod (especiaslly if it's not connected).
    Removing iTunes will also not delete any music files
    from the computer.
    Use Control Panel to remove iTunes.
    Restart the computer, then reinstall it.
    Thanks Chris for your prompt reply !, but won't removing itunes from my computer also delete the synchronised library, meaning that when I reinstall, and then reconnect the ipod to the computer, it will lead to the files on the ipod being deleted ?
    Kind regards
    Peter

  • Should be an easy one...

    I have two questions.
    1) I have shot at 24p and 30p. When I import from the camera should I change the import settings depending on which takes match up with the frame rates? My guess is yes, but I want to confirm
    2) If the majority of the work is 24p and I have a few 30p shots, how do the 30p shots work into the sequence of the existing 24p shots? Do I need to make two sequences or will rendering take care of this?

    Give us a few more days for some of the 24fps wonks to check in and offer some advice. The first thing they're going to ask is what camera and what format? We see many such posts, often from folks who have set their camera to do a cine-look frame rate that is merely baked into a 30 fps tape format.
    bogiesan

Maybe you are looking for

  • Single sign on and microsoft active directory

    Hi, I have EBS 12.1.3 on linux. I know that I can implement single sign on to login to EBS. Now the question is: can I integrate this single sign on with my existing Microsoft Active Directory? Can you send me some links or documentation?

  • Down payment of assets with purchase order

    Hi All, Down payment made through F-48 against  asset purchase order When purchase order number is entered,it is picking the Asset number  and it is capitalising at the time of down payment. i have gone through the Sap Note number 310368 in detial an

  • How to include .css file into jsp file in portal application

    Hi, I have included a .css file in a .jsp file using following tag : <link rel="<%=componentRequest.getWebResourcePath()%>/css/ts.css">. I have kept .css file under /dist/css folder. Preview of jsp file is fine but when I upload the jsp file and .css

  • How can I get Safari 5.1 to open without opening all the tabs that were open when i last quit safari?

    When I lauch Safari (5.1 in 10.7) I want it to open to either an empty page or a designated homepage - but istead it opens all the tabs that were open when I quit Safari.  How do i stop this, I cant find any preference to achieve this and see nothing

  • Adding actual signatures to email

    This question is directed to FrankBe specifically, or to anyone who has personalized mail. How did you create your signature? thanks.