code_junkie

Java NullPointerException when traversing a non-null recordset

Nov 13th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. output.print(rs.getString(1));
  2.  
  3. preparedStatement.setLong(1, primaryKey);
  4. ResultSet rs = preparedStatement.executeQuery();
  5. while (rs.next())
  6. {
  7. String foo = rs.getString(1);
  8. if (foo != null)
  9. ...
  10. }
  11.  
  12. while (rs.next()){
  13. try{
  14. output.write(rs.getDate(2) + " " + timeFormat.format(rs.getTime(2)) + "|");
  15. ....
  16. }
  17. catch(IOException e){//error handling code}
  18. }
  19.  
  20. Exception in thread "main" java.lang.NullPointerException
  21. at com.sybase.jdbc3.timedio.RawDbio.reallyRead(Unknown Source)
  22. at com.sybase.jdbc3.timedio.Dbio.doRead(Unknown Source)
  23. at com.sybase.jdbc3.timedio.InStreamMgr.a(Unknown Source)
  24. at com.sybase.jdbc3.timedio.InStreamMgr.doRead(Unknown Source)
  25. at com.sybase.jdbc3.tds.TdsProtocolContext.getChunk(Unknown Source)
  26. at com.sybase.jdbc3.tds.PduInputFormatter.a(Unknown Source)
  27. at com.sybase.jdbc3.tds.PduInputFormatter.read(Unknown Source)
  28. at com.sybase.jdbc3.tds.TdsInputStream.read(Unknown Source)
  29. at com.sybase.jdbc3.utils.CacheStream.read(Unknown Source)
  30. at com.sybase.jdbc3.tds.TdsInputStream.read(Unknown Source)
  31. at com.sybase.jdbc3.tds.TdsInputStream.readInt(Unknown Source)
  32. at com.sybase.jdbc3.tds.TdsDataObject.readDATETIMN(Unknown Source)
  33. at com.sybase.jdbc3.tds.TdsJdbcInputStream.getDateObject(Unknown Source)
  34. at com.sybase.jdbc3.jdbc.SybResultSet.getDate(Unknown Source)
  35. at <removed>.processResults(ProcessRecords.java:118)
  36. at <removed>.Main.main(Main.java:65)
Add Comment
Please, Sign In to add comment