LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SQL Server The column name is not valid (https://www.linuxquestions.org/questions/programming-9/sql-server-the-column-name-is-not-valid-4175726587/)

mfoley 07-03-2023 08:02 PM

SQL Server The column name is not valid
 
Normally I'd ask this question on the Micosoft answers forum, but since they now want me to download the Microsoft Authenticator app to my phone, I'm not interested. LQ people seem to know stuff like this so I'll try here.

I'm running Slackware64 14.2, Java 17.0.2 and Tomcat10.0.17.

I'm running a query in java/jsp which is giving me an error:
Code:

select a.allocationAmount, c.totalCredit
from WTWpreMedicareSvcAmount a
left join vwWTWpreMedicareServiceCredit c on c.memberId = '123456'
where a.effYear = 2023 and a.serviceCredit = case when c.totalCredit is null then 20 when c.totalCredit > 30 then 30 else c.totalCredit end

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The column name totalCredit is not valid.

Yet if I run this query using just java it works:
Code:

select a.allocationAmount, c.totalCredit
from WTWpreMedicareSvcAmount a
left join vwWTWpreMedicareServiceCredit c on c.memberId = '123456'
where a.effYear = 2023 and a.serviceCredit = case when c.totalCredit is null then 20 when c.totalCredit > 30 then 30 else c.totalCredit end

allocationAmount totalCredit
---------------- ----------------------------------------
480.0000

Any idea why I get the column name not valid when run within jsp? I believe both Java and jsp are using sqljdbc42.jar.

NevemTeve 07-03-2023 11:49 PM

Did you paste the same code twice? Even so, these might be two different databases, only one of them having this field.

grail 07-04-2023 09:39 AM

I am with NevemTeve, I see 2 select queries and no java / jsp??

sundialsvcs 07-04-2023 01:55 PM

Instinctively, I'd suggest that you look for "a 'DOH!' :doh: situation" right about now. Check very carefully that you are in fact presenting an identical query, to the same database, in both (very different ...) situations.

mfoley 07-12-2023 09:15 AM

sundialsvcs was right, "a 'DOH!' :doh: situation". I have two ResultSet variables in my program, and this query used the 2nd one, rs2. However, when I went to get the column totalCredit I did rs.getBigDecimal("totalCredit") instead of rs2.getBigDecimal(...). Posting the actual code would probably have helped everyone see my error, but I've become gun-shy of posting code on LQ as I often get such posts rejected.

Anyway, thanks all for the help.

sundialsvcs 07-12-2023 11:15 PM

("Chuckle ...") Good sir, by now my forehead is perfectly smooth as the result of such physical encounters.

- - -

Shhh!! Don't let them know! They still believe that we are all geniuses! ;)


All times are GMT -5. The time now is 10:41 PM.