• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Vector from bean to servlet?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();"
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic