File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring + JDBC + Servlet" Watch "Spring + JDBC + Servlet" New topic

Spring + JDBC + Servlet

tatiana erm

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


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

Joined: Feb 05, 2001
Posts: 17276

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


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.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Spring + JDBC + Servlet
jQuery in Action, 3rd edition