You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by "Kessler, Joerg" <jo...@sap.com> on 2014/09/09 10:20:11 UTC

Problem with Select statement

Hi,
I want to execute select statement on a table using a Java program and JDBC. The statement is actually not very difficult:
SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM TESTTABLE  WHERE SEQ_ID = ? AND (MSGSTATE IS NULL OR MSGSTATE = 'A')
When this statement is executed by a test I receive errors like

Column 'A' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'A' is not a column in the target table.

When I change the statement to
SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM TESTTABLE  WHERE SEQ_ID = ? AND MSGSTATE IS NULL
there is no problem. Also when I execute the above statement via Eclipse Database Development/SQL Scrapbook using a fix SEQ_ID the statement is executed without error.

What am I doing wrong?

Best Regards,

Jörg

RE: Problem with Select statement

Posted by "Kessler, Joerg" <jo...@sap.com>.
Thanks,
you are right. That seems to be the only thing I did not check. I did not expect that the string gets changed. I have to figure out why this happens.

Best regards,
Jörg

-----Original Message-----
From: Dyre Tjeldvoll [mailto:Dyre.Tjeldvoll@oracle.com] 
Sent: Dienstag, 9. September 2014 11:23
To: derby-user@db.apache.org
Subject: Re: Problem with Select statement

On 09/09/2014 10:20 AM, Kessler, Joerg wrote:
> Hi,
>
> I want to execute select statement on a table using a Java program and
> JDBC. The statement is actually not very difficult:
>
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM
> TESTTABLE  WHERE SEQ_ID = ? AND (MSGSTATE IS NULL OR MSGSTATE = 'A')

What does the Java String value passed to prepareStatement() look like? 
Sounds like your single-quotes around A have been eaten somehow...


>
> When this statement is executed by a test I receive errors like
>
> Column 'A' is either not in any table in the FROM list or appears within
> a join specification and is outside the scope of the join specification
> or appears in a HAVING clause and is not in the GROUP BY list. If this
> is a CREATE or ALTER TABLE  statement then 'A' is not a column in the
> target table.
>
> When I change the statement to
>
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM
> TESTTABLE  WHERE SEQ_ID = ? AND MSGSTATE IS NULL
>
> there is no problem. Also when I execute the above statement via Eclipse
> Database Development/SQL Scrapbook using a fix SEQ_ID the statement is
> executed without error.
>
> What am I doing wrong?
>
> Best Regards,
>
> Jörg
>


-- 
Regards,

Dyre

Re: Problem with Select statement

Posted by Dyre Tjeldvoll <Dy...@oracle.com>.
On 09/09/2014 10:20 AM, Kessler, Joerg wrote:
> Hi,
>
> I want to execute select statement on a table using a Java program and
> JDBC. The statement is actually not very difficult:
>
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM
> TESTTABLE  WHERE SEQ_ID = ? AND (MSGSTATE IS NULL OR MSGSTATE = 'A')

What does the Java String value passed to prepareStatement() look like? 
Sounds like your single-quotes around A have been eaten somehow...


>
> When this statement is executed by a test I receive errors like
>
> Column 'A' is either not in any table in the FROM list or appears within
> a join specification and is outside the scope of the join specification
> or appears in a HAVING clause and is not in the GROUP BY list. If this
> is a CREATE or ALTER TABLE  statement then 'A' is not a column in the
> target table.
>
> When I change the statement to
>
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM
> TESTTABLE  WHERE SEQ_ID = ? AND MSGSTATE IS NULL
>
> there is no problem. Also when I execute the above statement via Eclipse
> Database Development/SQL Scrapbook using a fix SEQ_ID the statement is
> executed without error.
>
> What am I doing wrong?
>
> Best Regards,
>
> Jörg
>


-- 
Regards,

Dyre

Re: Problem with Select statement

Posted by Peter Ondruška <pe...@yahoo.com>.
Hello,

can you describe your table testtable please?

On 9 Sep 2014, at 10:20, Kessler, Joerg <jo...@sap.com> wrote:

> Hi,
> I want to execute select statement on a table using a Java program and JDBC. The statement is actually not very difficult:
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM TESTTABLE  WHERE SEQ_ID = ? AND (MSGSTATE IS NULL OR MSGSTATE = 'A')
> When this statement is executed by a test I receive errors like
>  
> Column 'A' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'A' is not a column in the target table.
>  
> When I change the statement to
> SELECT MSG_NO, SEND_TO, CREATED_TIME, CONTENT, ENCRYPTION_KEY FROM TESTTABLE  WHERE SEQ_ID = ? AND MSGSTATE IS NULL
> there is no problem. Also when I execute the above statement via Eclipse Database Development/SQL Scrapbook using a fix SEQ_ID the statement is executed without error.
>  
> What am I doing wrong?
>  
> Best Regards,
>  
> Jörg