1、利用BeanUtils的前提得要加入以下两个jar包:
commons-beanutils-1.8.0.jar
commons-logging-1.1.1.jar
package com.shellway.jdbcDAO; import java.util.List; import org.junit.Test; public class TestDAO { DAO dao = new DAO(); @Test public void testUpdate() throws Exception { String sql = "update examstudent set grade=? where flow_id=12345"; dao.update(sql, 88); } @Test public void test() throws Exception { String sql = "select flow_id flowID,type,id_card idCard, " + "exam_card examCard,student_name studentName,location,grade " + "from examstudent where flow_id = ? "; Student stu = dao.get(Student.class, sql, 12345); System.out.println(stu); } @Test public void testGetSome() throws Exception { String sql = "select flow_id flowID,type,id_card idCard, " + "exam_card examCard,student_name studentName,location,grade " + "from examstudent"; List<Student> students = dao.getForList(Student.class, sql); System.out.println(students); } @Test public void testGetForValue() throws Exception { String sql = "select grade from examstudent where flow_id = ? "; Object obj = dao.getforvalue(sql, 123456); System.out.println(obj); } }