+ -
当前位置:首页 → 问答吧 → 大家看一下这段代码是不是有什么错误呀

大家看一下这段代码是不是有什么错误呀

时间:2011-11-29

来源:互联网

public static User getUser(String name) {//前提user必在数据库中
User user=null;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try {
conn=DB.getConn();
stmt=DB.createStmt(conn);
rs=stmt.executeQuery("select * from user where name='"+name+"'");
if(rs.next()) {
user=new User();
user.setEmail(rs.getString("email"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setTimeAllow(rs.getInt("timeallow"));
user.setTotal(rs.getInt("total"));
user.setNownum(rs.getInt("nownum"));
}
DB.close(rs);
DB.close(stmt);
DB.close(conn);
} catch (SQLException e) {
System.err.println(e);
} finally {
if(rs!=null)
DB.close(rs);
if(stmt!=null) 
DB.close(stmt);
if(conn!=null) 
DB.close(conn);
}
return user;
}

作者: java___learn   发布时间: 2011-11-29

有可能返回NULL

作者: llqzy   发布时间: 2011-11-29

你究竟想问什么?

作者: mrwangxiao0605   发布时间: 2011-11-29

怎么避免呢?
引用 1 楼 llqzy 的回复:
有可能返回NULL

作者: java___learn   发布时间: 2011-11-29

我的一个图书管理系统在借书处出现了HTTP Status 500 - 错误,经过排查,感觉是这里有问题。但又不知道哪里有问题。
引用 2 楼 mrwangxiao0605 的回复:
你究竟想问什么?

作者: java___learn   发布时间: 2011-11-29

单步,就知道哪里问题了

作者: lxwankkk   发布时间: 2011-11-29

热门下载

更多