Announcement Announcement Module
Collapse
No announcement yet.
getting null pointer exception while using jdbc template Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • getting null pointer exception while using jdbc template

    Dear friends ,
    i am new in spring an making one demo application.
    i m getting the below mentioned error when i m inserting ;;

    Error is --->java.lang.NullPointerException
    java.lang.NullPointerException
    at com.tcs.sgv.dao.CustomerDAOImpl.saveCustInfo(Custo merDAOImpl.java:26)
    at com.tcs.sgv.controller.SpringAppController.handleR equestInternal(SpringAppController.java:60)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:857)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:792)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:475)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:440)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)



    below is the code of my class in which i m using it

    public class CustomerDAOImpl //implements CustomerDAO
    {
    private JdbcTemplate jdbcTemplate;

    public void setDataSource(DataSource dataSource)
    {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    }
    public void saveCustInfo(Customer cust)
    {
    final String sql="insert into cust_mst(Cust_Id,Cust_Name,Dept_Name) values(?,?,?)";

    Object[] params=new Object[]{cust.getCustId(),cust.getCustName(),cust.getDeptN ame()};
    try
    {

    this.jdbcTemplate.update(sql,params);
    }
    catch(Exception e)
    {
    System.out.println("Error is --->"+e);
    e.printStackTrace();
    }

    }


    an below is config file :--


    <bean id="customerDAOImpl" class="com.tcs.sgv.dao.CustomerDAOImpl">
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="Customer" class="com.tcs.sgv.dao.Customer"/>

    <!-- bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg>
    <ref bean="dataSource" />
    </constructor-arg>
    </bean-->

    <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@172.26.136.161:1521:iwash yd"/>
    <property name="username" value="iwas_admin"/>
    <property name="password" value="cmndev"/>
    </bean>



    plz tell me the solution as i m stuck with this prob since last two days....

  • #2
    Use [ code][/code ] tags when posting code.

    Don't create an instance of the dao in your controller, inject it.

    Comment


    • #3
      thank you very much buddy my issue got solved

      Comment

      Working...
      X