Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2015
    Posts
    2

    Answered: Problem with SELECT... WHERE statement

    Hello all! I am having a problem with a SELECT... WHERE statement. If I just do a simple SELECT statement I can pull data from the table, however if I try to add a WHERE clause to this SELECT, I receive an Error: DB2 SQL Error: SQLCODE = -206, SQLSTATE=42703. After looking around I think I know that this error means that the column I'm trying to use in the WHERE clause could not be located. However data is pulled from that column when just the SELECT is run. Any suggestions?

    For clarification:

    This works
    Code:
    resultset = statement.executeQuery("SELECT * FROM USERS");
    			
    			while( resultset.next())
    			{
    				String f_name = resultset.getString("f_name");
    				String l_name = resultset.getString("l_name");
    				String username = resultset.getString("username");
    				String password = resultset.getString("password");
    				
    				System.out.printf("First: %s\tLast: %s\t Username: %s\tPassword: %s", f_name, l_name, username, password);
    			}
    but if the query is changed to (SELECT * FROM USERS WHERE username = 'whatever username I want to look up'), I get Error: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=USERNAME, DRIVER=3.68.61.

    Thanks for any help!

  2. Best Answer
    Posted by mark.b

    "Hello,

    Can you provide exact DDL of your table?
    Table could be created with column "username" in lowercase letters using double quotes around the column name like:
    Code:
    create table users ("username" varchar(...), ...) ...
    You have to surround your column name with double quotes in this case as well in the SELECT statement like:
    Code:
    resultset = statement.executeQuery("SELECT * FROM USERS where \"username\"='whatever username I want to look up'");
    "


  3. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hello,

    Can you provide exact DDL of your table?
    Table could be created with column "username" in lowercase letters using double quotes around the column name like:
    Code:
    create table users ("username" varchar(...), ...) ...
    You have to surround your column name with double quotes in this case as well in the SELECT statement like:
    Code:
    resultset = statement.executeQuery("SELECT * FROM USERS where \"username\"='whatever username I want to look up'");
    Regards,
    Mark.

  4. #3
    Join Date
    Feb 2015
    Posts
    2
    Mark,

    That was exactly what happened! Thank you so much for your response.

    Best,
    -Austin

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •