在商品逻辑类中的一个方法搞不定~~
这一段是ItemsDAO商品逻辑类中根据ID返回商品信息的方法,,一点一点码上去的不是复制粘贴的,和老师讲的一模一样,它提示我please add return statement,为何?
public Items getItemsById (int id) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DBHelper.getConnection();
String sql = "select * from items where id=?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, id);
rs = stmt.executeQuery();
if (rs.next()) {
Items item = new Items();
item.setCity(rs.getString("city"));
item.setId(rs.getInt("id"));
item.setName(rs.getString("name"));
item.setNumber(rs.getInt("number"));
item.setPicture(rs.getString("picture"));
item.setPrice(rs.getInt("price"));
return item;
}else{
return null;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (stmt != null) {
try {
stmt.close();
stmt = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
rs = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}