简体   繁体   中英

Null pointer exception when getting the value from query in java

I am fetching the value using query

SELECT t.revision_no 
FROM (
    SELECT MAX( CONVERT( revision_no, signed INT ) ) AS revision_no 
    FROM atps_dc 
    WHERE DATE =  '"+date+"' 
    GROUP BY CONVERT( revision_no, signed INT )) 
INNER JOIN atps_dc t 
ON t.revision_no = r.revision_no AND t.date =  '"+date+"'";

and trying to set this value using this

bA.setRev_no(rs2.getString("revision_no"));

but the compiler is giving the null pointer exception. Please help me, how can I resolve it.

Thanks in advance.

compiler doesn't give NullPointerException it is RuntimeException , You are pointing bA to null and then trying to invoke method on it and so the NullPointerException

DC_ChangeA bA=null; 
bA.setRev_no(rs2.getString("revision_no"));

try DC_ChangeA bA = new DC_ChangeA() or proper initialization in the place of DC_ChangeA bA = null


See

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