java - Handle Nullpointerexception after SQL query has no result -
i've got mvc based java application 3 models: room, student , studentroom.
studentroom contains object of room , student.
now i've got problem if sql query returns no result , check value of student's name this
if(studentroom.student.name != null) { } i'll nullpointerexception , don't know how handle it.
should set student.name = ""; since query has no result?
if(studentroom != null && studentroom.student != null && studentroom.student.name != null){ //.. access student } above solution looks bit weird. should better use getter/setter methods instead of directly accessing objects.
apart can define methods isstudentavailable() in studentroom check whether has student in or not.
should set student.name = ""; since query has no result ?
it depends on use case. must better keep null raise exception instead of passing null check validations.
Comments
Post a Comment