空指针public List<Transfer> getAllDestination() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select distinct destination from transfer;";
List<Transfer> dataList = new ArrayList<Transfer>();
try {
conn = DataBaseManager.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Transfer transfer = new Transfer();
transfer.setDestination(rs.getStrin("destination"));//这里老是抛出空指针错误。主要是在运行前台的时候。后台代码测试一点问题都没有。这是为什么呢?struts2.0的框架。
dataList.add(transfer);
}
DataBaseManager.close(rs);
DataBaseManager.close(ps);
} catch (
SQLException e) {
e.printStackTrace();
} finally {
DataBaseManager.closeConn();
}
return dataList;
}
------解决方案--------------------rs.getStrin--->rs.
getString------解决方案--------------------打个断点debug下
------解决方案--------------------你这个根本编译就会出错
rs.getStrin
g("destination")
rs.getStrin = rs.getString
------解决方案--------------------你关闭写在
} finally {
xxx.close(conn, ps, rs);
}
------解决方案--------------------你得首先判断RS是不是为null