This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Spring and the fly likes;)Ljava/la Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Spring
Bookmark ";)Ljava/la" Watch ";)Ljava/la" New topic

vineet kaushik

Joined: Aug 05, 2009
Posts: 13
Hi Guys,

Having used JdbcTemplate I was working on NamedParameterJdbcTemplate with queryForInt(sql,sqlParamSource) method and getting below error .

Exception in thread "main" java.lang.NoSuchMethodError:;)Ljava/lang/Object;
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForInt(
at dao.EmpDaoImpl_new.getNoEmployee(
at main.EmpMainNamed.getNoEmployee(
at main.EmpMainNamed.main(

and Please see my code below..


<?xml version="1.0" encoding="UTF-8"?>

<bean id="datasource"
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="sys" />


<bean id="empDao_new" class="dao.EmpDaoImpl_new">
<ref local="datasource" />

package dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import com.Interface.*;
import com.Model.Employee;;

public class EmpDaoImpl_new implements EmpDao{

NamedParameterJdbcTemplate namedParameterJdbcTemplate;

public EmpDaoImpl_new() {
// TODO Auto-generated constructor stub
public EmpDaoImpl_new(DataSource ds ) {
this.namedParameterJdbcTemplate=new NamedParameterJdbcTemplate(ds);

public Employee getEmpById(int eno) {
// TODO Auto-generated method stub
return null;
public int getNoEmployee(String first_name) {
String sql="select count(0) from employee where first_name= :firstName";
SqlParameterSource sqlParamSource=new MapSqlParameterSource("firstName",first_name);
int noEmployee=namedParameterJdbcTemplate.queryForInt(sql,sqlParamSource);
return noEmployee;

package main;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;

import com.Interface.EmpDao;

public class EmpMainNamed {

BeanFactory beanFactory;

EmpDao empDAO;

public EmpMainNamed() {

beanFactory = new XmlBeanFactory(new FileSystemResource("src/mybeans.xml"));
empDAO = (EmpDao) beanFactory.getBean("empDao_new");

public static void main(String[] args) {
EmpMainNamed obj = new EmpMainNamed();

public void getNoEmployee(String first_Name) {
int empCount = empDAO.getNoEmployee(first_Name);
System.out.println("Number of employees aginst " + first_Name + " is "
+ empCount);


package com.Interface;

import java.util.List;

public interface EmpDao {

public int getNoEmployee(String first_name);


NOte:- Datasource is NamedParameterJdbcTemplate is being pulled correctly. and It is generating error while invoking queryForInt(sql,sqlParamSource).

Quick response is deeply appreciated.


Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

Make sure you are using the same Spring jars versions of compile/runtime dependencies.
vineet kaushik

Joined: Aug 05, 2009
Posts: 13

Your suggestion worked for me .

Have you checked out Aspose?
It's not a secret anymore!