public boolean userLogin() throws Exception {
boolean flag = false;
PreparedStatement pStmt=null;
ResultSet result=null;
try {
//conn 数据库连接 在构造函数的时候创建,并已经处理的可能的异常
pStmt = conn.prepareStatement("select count(*) from users where cUserName=? and cUserPassword=?");
pStmt.setString(1, userName);
pStmt.setString(2, userPassword);
result = pStmt.executeQuery();
while(result.next()) {
if(result.getInt(1)==1) {
flag = true;
} else {
flag = false;
}
}
} catch(Exception e) {
e.printStackTrace();
} finally {
//这个地方这样判断不晓得对不对?
if(result!=null) {
result.close();
pStmt.close();
conn.close();
}
}
return flag;
}
boolean flag = false;
PreparedStatement pStmt=null;
ResultSet result=null;
try {
//conn 数据库连接 在构造函数的时候创建,并已经处理的可能的异常
pStmt = conn.prepareStatement("select count(*) from users where cUserName=? and cUserPassword=?");
pStmt.setString(1, userName);
pStmt.setString(2, userPassword);
result = pStmt.executeQuery();
while(result.next()) {
if(result.getInt(1)==1) {
flag = true;
} else {
flag = false;
}
}
} catch(Exception e) {
e.printStackTrace();
} finally {
//这个地方这样判断不晓得对不对?
if(result!=null) {
result.close();
pStmt.close();
conn.close();
}
}
return flag;
}
解决方案 »
- 在java中生成一维码问题
- 急!急!急!求教在使用setProperty设置value值的时候出错了!
- ecside editTemplate 数据验证
- jsp视频点播
- JSP新手 导入class的时候提示malformed floating point literal
- 请教jsp连接数据库取得数据后用jfreechart在web页面显示图表问题
- 请教JSP网站开发几点问题
- 求帮忙设置一下,新建项目看不见
- 大侠们,我想做一个象csdn界面左边的树,请高手提供源码或给予指点??
- 薪水调查.不介意吧!?
- webwork2.2.2+spring1.2.8+hibernate3.0 如何配置运行在Tomcat5.5.12?
- 求一个将文件复制并重命名的脚本
try {
result.close();
pStmt.close();
conn.close();
} catch(Exception e) {
e.printStackTrace();
} }这样写是不是好些
if(result.next()) {
flag = true;
}
不需要楼主那么麻烦。。