aspose file tools*
The moose likes Spring and the fly likes org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/la Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/la" Watch "org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/la" New topic
Author

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

vineet kaushik
Greenhorn

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: 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

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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

Joined: Aug 05, 2009
Posts: 13
Thanks,

Your suggestion worked for me .

-Vineet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/la