2
回答
BeanHandler返回结果全为NULL
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

很简单的测试BeanHandler,结果却全为NULL,是什么原因

public static void main(String[] args) {
		Connection db = null;
		DbUtils.loadDriver("com.mysql.jdbc.Driver");
		String sql3 = "select * from province";
			try{			
				db = DriverManager.getConnection("jdbc:mysql://localhost:3306/software","root","root");
				QueryRunner qr = new QueryRunner();	
				ResultSetHandler bh = new BeanHandler(province.class);
				province p = (province)qr.query(db, sql3, bh);
				System.out.println(p.getName());
		
			}
			catch(Exception e){
				e.printStackTrace();
			}
			DbUtils.closeQuietly(db);
	}
package user;

public class province {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
其它的比如MapHandler,ScalarHanlder都能返回正确值,就是封装成Bean的时候返回结果为NULL

举报
allenfor
发帖于5年前 2回/707阅
顶部