public boolean findUser(UserInfoDTO user)
{
Connection conn=null;
PreparedStatement statement=null;
ResultSet rs=null;
try
{
conn=DBUtil.getConnection();
statement=conn.prepareStatement("select * from UserInfo where userID=? and userPassword=?");
statement.setString(1,user.getUserID());
statement.setString(2,user.getUserPassword());
rs=statement.executeQuery();
if(rs.next())
{
return true;
}
else{
return false;
}
}
catch(Exception ex)
{
System.out.println("数据库操作失败!");
}
finally
{
try
{
rs.close();
statement.close();
conn.close();
}
catch(Exception ex1)
{
System.out.println("数据库关闭失败!");
}
}
return false;//???这是干啥的?,为啥注释掉还报错
}
{
Connection conn=null;
PreparedStatement statement=null;
ResultSet rs=null;
try
{
conn=DBUtil.getConnection();
statement=conn.prepareStatement("select * from UserInfo where userID=? and userPassword=?");
statement.setString(1,user.getUserID());
statement.setString(2,user.getUserPassword());
rs=statement.executeQuery();
if(rs.next())
{
return true;
}
else{
return false;
}
}
catch(Exception ex)
{
System.out.println("数据库操作失败!");
}
finally
{
try
{
rs.close();
statement.close();
conn.close();
}
catch(Exception ex1)
{
System.out.println("数据库关闭失败!");
}
}
return false;//???这是干啥的?,为啥注释掉还报错
}
解决方案 »
- 窗体激活
- ★☆java收我用vb+winsock写的数据有问题~收到null,或是关闭winsock后才能收到★☆
- how do I continue writing binary data to an existing binary saved file?
- 请问.....
- 这是java未公开的写法么?
- 请教!怎么把自己载的doc链到jbuilder里!
- 菜鸟问题:怎样正确设置jdk路径及class路径?
- client/server編程中的問題
- mysql创建用户、数据库
- 用Java反射,对B对象进行深度复制,B中含有List<A >属性,A 要求实例化为a ,再调用 a.setxx(B); 如何实现?
- 关于线程安全的疑问
- 还是关于java泛型的问题:在静态方法中为什么不能引用类级别的类型参数?
try块里面的语句等于是局部的一样.外面没有办法访问到..
根据你的函数,我验证了一下,由于你上面的try语句里 面已经有返回值,最后一条return语句不执行。范例:public class First { public static void main(String[] args)
{
int a=5;
int b=1;
if(new First().compare(a,b)){
System.out.println("you are right!");
}
} public boolean compare(int a1 ,int b1)
{
try{
if(a1>b1)
{
return true;
}
else{
}
}
catch(Exception e){}
finally{}
return false;
}
}
该方法定义了返回类型是boolean,所以必须要返回一个boolean值。
有时候在判断中出现某种情况的时候 return一下表示下面不执行了。在js中验证中 用的最多了
2.finally有return时,不管有没有异常,都会从finally的return跑掉----try块有return。没有异常(不进入catch块)时,finally块有return走finally,否则走try的return。--------外层有也不走,其实是运行到try的return时,执行finally在返回try的return,但是finally也有return,所以相当于半路跑路了----try块有return。有异常(进入catch块)时,finally块有return走finally,否则走catch的return。--------解释同上,到finally时半路跑路了。测试代码----->传送门