File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Spring + JDBC + Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring + JDBC + Servlet" Watch "Spring + JDBC + Servlet" New topic
Author

Spring + JDBC + Servlet

tatiana erm
Greenhorn

Joined: Jul 11, 2012
Posts: 5
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring + JDBC + Servlet