java - Why is the returned ResultSet null -
given table structure:
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
Post a Comment