• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector from bean to servlet?

 
Ram Luchman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting nullpointer exception when I pass a resultset turned into vector from a bean to a servlet. I can pass the vector from the bean to a JSP page without problems. My code below. The error happens at this point "rs = (Vector)d.getQueryresult();"
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One minor point, you shouldn't need to cast (Vector), because the return type of the method is a Vector.

The other thing is when you are building your query, you don't leave a space between the tablename and the WHERE clause.

If you printed the contents of the String 'q', you'd get "SELECT * FROM EmployeesWHERE userID = etc, etc...

Your try-catch-finally in your bean appears to be good, so I'd expect you would find the SQLException stack trace in your log. the 'return v' is in your finally block, so that should be ok.

What about the stack trace you do see? Can you post it?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait, it's not in the finally block.

In the bean class, the line that would throw the exception from a malformed query string is:

rs = st.executeQuery(query);

but only after that do you make the new vector.

v = new Vector();

Then below, when you attempt:

v.trimToSize(); This line should throw a NullPointerException
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic