简体   繁体   中英

null point exception if not having value in array

Client:

for(int j=0;j<prod10.length;j++){
            String ret_val ="";
            bean.setProd10(prod10[j]);
            ret_val=build.saveRSupplier(bean);

        }

DAO:

if(rs.next()){
                String sum=rs.getString("max(patient_no)+1");
                String q7="insert into new8(ok, reference)"
                        + " values('"+sum+"','"+purid10+"')";
                PreparedStatement p7 = con.prepareStatement(q7);
                int s7 = p7.executeUpdate();        
            }

if i put value in array then by using prod10 it set the length and array of data are stored in the database but if i do not put value in array null point exception occur,this should not have to happen what i should have to do for this

I presume your prod10 array is null . Have a null check before the for loop.

if(null != prod10) {
for(int j=0;j<prod10.length;j++){
            String ret_val ="";
            bean.setProd10(prod10[j]);
            ret_val=build.saveRSupplier(bean);

        }
}

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