public class TestItem {
public static void main(String[] args){
//注意:如果使用该测试程序,则不能使用jndi连接池操作,必须使用jdbc操作,所以要进行更
//改applicationContext.xml中的配置文件,同时应将相应的驱动包添加到lib目录下,tomcat
//中也应添加相应的数据库驱动包
ApplicationContext cts = new ClassPathXmlApplicationContext("applicationContext.xml");
IItemDAO id = (IItemDAO)cts.getBean("iitemdaoimpl");
try {
System.out.println(id.queryAll());
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文介绍了一个使用Spring框架进行数据库访问的具体示例。通过ClassPathXmlApplicationContext加载配置文件applicationContext.xml,并从上下文中获取IItemDAO实例,进而调用其queryAll方法来展示如何查询所有数据。
903

被折叠的 条评论
为什么被折叠?



