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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/la

 
Greenhorn
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: org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/lang/Object;
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:152)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:164)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForInt(NamedParameterJdbcTemplate.java:191)
at dao.EmpDaoImpl_new.getNoEmployee(EmpDaoImpl_new.java:46)
at main.EmpMainNamed.getNoEmployee(EmpMainNamed.java:27)
at main.EmpMainNamed.main(EmpMainNamed.java:23)


and Please see my code below..

mybeans.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">;
<beans>

<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<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>

<bean id="empDao_new" class="dao.EmpDaoImpl_new">
<constructor-arg>
<ref local="datasource" />
</constructor-arg>
</bean>
</beans>

EmpDaoImpl_new.java


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;
}
}

EmpMainNamed.java


package main;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

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();
obj.getNoEmployee("RAM");
}

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

}
}


EmpDao.java

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.

Thanks,
Vineet

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

Your suggestion worked for me .

-Vineet
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic