日期:2014-05-16 浏览次数:20537 次
ResultSetHandler h = new KeyedHandler("id"); Map found = (Map) queryRunner.query("select id, name, age from person", h); Map jane = (Map) found.get(new Long(1)); // jane's id is 1 String janesName = (String) jane.get("name"); Integer janesAge = (Integer) jane.get("age");
CREATE TABLE person ( id bigint(20) NOT NULL AUTO_INCREMENT, name varchar(24) DEFAULT NULL, age int(11) DEFAULT NULL, address varchar(120) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=gbk?
public class Person { private Long id; private String sdf; private String address2; private Integer age; public Person() { } public Person(String sdf) { this.sdf = sdf; } public Person(String sdf, Integer age, String address) { this.sdf = sdf; this.age = age; this.address2 = address; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getSdf() { return sdf; } public void setSdf(String sdf) { this.sdf = sdf; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getAddress() { return address2; } public void setAddress(String address2) { this.address2 = address2; } }?
package com.lavasoft.dbstu; import com.lavasoft.common.DBToolkit; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanHandler; import org.apache.commons.dbutils.handlers.BeanListHandler; import org.apache.commons.dbutils.handlers.MapHandler; import org.apache.commons.dbutils.handlers.ScalarHandler; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import java.util.Map; /** * Created by IntelliJ IDEA. * * @author leizhimin 2010-1-25 21:00:29 */ public class PersonDAOImpl implements PersonDAO { private static PersonDAOImpl instance