I am new to Spring and I am trying to learn how to use the JdbcTemplate first. I have a project that I need done ASAP.
Here is my sample code:
package com.springinaction.chapter01.hello;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFacto ry;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
public class HelloApp {
public static void main(String[] args) throws Exception {
BeanFactory factory =
new XmlBeanFactory(new ClassPathResource("hello.xml"));
GreetingService greetingService =
(GreetingService) factory.getBean("greetingService");
greetingService.sayGreeting();
JdbcTemplate jdbc = new JdbcTemplate();
List commList = jdbc.queryForList("SELECT FIRST FROM NAMES");
Iterator commIter = commList.iterator();
while(commIter.hasNext())
{
String name = (String)((Map) commIter.next()).get("first");
System.out.println(name);
}
}
}
CAN SOMEONE PLEASE TELL ME WHY AM I GETTING THE FOLLOWING ERROR
Exception in thread "main" java.lang.IllegalArgumentException: No DataSource specified
at org.springframework.util.Assert.notNull(Assert.jav a:112)
at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:99)
at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:79)
at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:328)
at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:404)
at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:412)
at org.springframework.jdbc.core.JdbcTemplate.queryFo rList(JdbcTemplate.java:443)
at com.springinaction.chapter01.hello.HelloApp.main(H elloApp.java:23)
thanks


Reply With Quote
