• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring + JDBC + Servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get a value in a form from the jsp, then pass to the servlet, and then store it to the DB using Spring and JDBC

I constantly get a NullPointer exception in a line
rd.addResult(r) of my servlet (this line is supposed to make an instance of ResultDaoImpl and add it to DB )
i cannot understant why

i think the problem is in the way i am using spring beans and manage creating objects, i ask the community for some code review

details:


I have a JSP wich asks user to enter the expression paramenter



Here is a piece of a servlet:
It receives a Parameter from JSP (expression),
creates an object Result, sets the Result's value to "expression"
creates a jdbcTemplate
adds this



here is my ResultDaoImpl class:







my spring-config.xml:




My DAO Implementation class:





Best Regards, Tania.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I don't see anywhere you actually using Spring in your application. Especially when you have a line in your Servlet that creates your ResultDao.

new ResultDaoImpl();

Anyway, how are you starting up Spring. How are you getting your beans in your Servlet.

You say you get the NPE at

rd.addResult(r)


well if it is truly at that line means that rd is null.

But maybe the stack trace shows a line further in.

Please post your stack trace. Also have you tried running the debugger and seeing exaclty what is null.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic