java - Why is the returned ResultSet null -


given table structure:

enter image description here

i want basic details of user database, created resulset named rst (see code below). when iterate on rst returns null.

public resultset detail(string mobile) throws exception {     dbconnect(); // make connection      string sql = "select * profile mobile = ?";     preparedstatement pstmt = con.preparestatement(sql);     pstmt.setstring(1, mobile);     resultset rst = pstmt.executequery();     dbclose(); // connection closed     return rst; } 

now if iterate on rst after having received return, null value.

try {     resultset rst = new db().detail(mobile);     string fname = rst.getstring("firstname");     string lname = rst.getstring("lasttname");     string date = rst.getstring("dateofbirth");     system.out.println("first name : " + fname + "\nlast name : " + lname + "\ndate of birth : " + date); } catch (exception exc) {     exc.printstacktrace(); } 

output:

first name : null last name : null date of birth : null 

closing database connection cause close related objects (resultset , prepared statement). rs not valid after dbclose(); should read result set before closing connection.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -