Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown;)Ljava/la

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you are using the same Spring jars versions of compile/runtime dependencies.
vineet kaushik
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your suggestion worked for me .

sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic