简体   繁体   中英

JDBC ResultSet - Can't retrieve alias column

We have the follwing SQL-Query:

select Resa.ResID, Avgångdatum, Avgångtid, AvgångStad, AnkomstTid, AnkomstDatum, AnkomstStad, AntalPlatser, Kostnad,

    (select sum(Bokning.AntalBiljetter) from Bokning where Bokning.ResID = Resa.ResID) as EnkelBiljetter,

    (select sum(Bokning.AntalBiljetter) from Bokning where Resa.ResID in
        (select PaketResa.ResID from PaketResa where PaketResa.PaketID in
            (select PaketID from PaketResa where PaketResa.PaketID = Bokning.PaketID))) as PaketBiljetter

from Resa;

When we try to get the columns "Enkelbiljetter" and "PaketBiljetter" in java, with

Integer.parseInt(result.getObject("PaketBiljetter").toString()

It returns a nullpointerexception. We've tried adding the "? useOldAliasMetadataBehavior=true " to the connection-statement but the result is the same. Neither does putting the columnindex (10 and 11) in the getObject-method. We're using the 5.1.19 JDBC driver. Any suggestions?

It could be either your result or getObject(...) returning a null pointer. Since there's a getInt() method you should try this first:

result.getInt("PaketBiljetter")

and see what happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM