• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring + JDBC + Servlet

 
tatiana erm
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic