Spring基础知识1:spring2.5与jdbc整合demo
好久没写jdbc的相关代码了,都忘得差不多了,一直都在用hibernate,这次学习spring,书中有关于jdbc整合的章节,并且讲了很多,于是决定再次写有关jdbc代码。整个写的非常简单,具体如下:
?
第一步:引入相关的jar包
第二步:在spring中配置好数据源(bean.xml)
?
?
第三步:创建实体bean(说明:这里其实可以不要创建这个bean,为了方便还是创建了这个bean) Sort.java
package spring.test.service.junit;import org.junit.BeforeClass;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import spring.test.bean.Sort;import spring.test.service.SortDao;public class SortDaoImplTest {@BeforeClasspublic static void setUpBeforeClass() throws Exception {}@Testpublic void testDelete() {}@Testpublic void testFindById() {}@Testpublic void testInsert() {ApplicationContext context= new ClassPathXmlApplicationContext("beans2.xml");SortDao sortDao=(SortDao)context.getBean("sortDaoImpl");//sortDao.delete(0);Sort sort=new Sort();sort.setSid(0);sort.setTitle("首页");sort.setInfo("首页,欢迎光临");sortDao.insert(sort);System.out.println("the sort save success!");}@Testpublic void testUpdate() {}}?
?
?