大家看一下这段代码是不是有什么错误呀
时间: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;
}
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
有可能返回NULL
作者: java___learn 发布时间: 2011-11-29
我的一个图书管理系统在借书处出现了HTTP Status 500 - 错误,经过排查,感觉是这里有问题。但又不知道哪里有问题。
引用 2 楼 mrwangxiao0605 的回复:
你究竟想问什么?
你究竟想问什么?
作者: java___learn 发布时间: 2011-11-29
单步,就知道哪里问题了
作者: lxwankkk 发布时间: 2011-11-29
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28