Non-serializable field in serializable class (transient keyword)

I have a serializable class that extends Servlet

public class FileDownload extends HttpServlet{
  private static final long serialVersionUID = 1L;
  private ResultSet rset;

My Question is:

Is the rset object automatically converted as transient at compile- or run-time? or do I have to mark it explicitly as transient? (That is a warning brought up from my IDE JDeveloper).


No, the field is not neglected by serialization – you’ll get a if you try to serialize an instance of FileDownload. Mark it transient. Btw, what is a ResultSet doing as a field in a Servlet? This is not thread-safe. ResultSets should be local variables only, in any context.

Leave a Reply

Your email address will not be published. Required fields are marked *