haoztao 2012年10月29日
java多处返回问题

public boolean isWorkDay()
{
Connection connection = null;
Statement st = null;
ResultSet rs = null;
try
{
connection = JDBCHelperV2.getConnection();

String sql_workDay = sql_getHoliday;
sql_workDay = sql_workDay.replace("@type", "2");
rs = JDBCHelperV2.executeQuery(connection, sql_workDay);
while (rs.next())
{
return true;
}

String sql_holiday = sql_getHoliday;
sql_holiday = sql_holiday.replace("@type", "1");
rs = JDBCHelperV2.executeQuery(connection, sql_holiday);
while (rs.next())
{
return false;
}

rs = JDBCHelperV2.executeQuery(connection, sql_getDayOfWeek);
while (rs.next())
{
String temp = rs.getString("weekday");
if (temp.equals("7") || temp.equals("1"))
{
return false;
}
return true;
}
}
catch(SQLException sqle)
{
throw new RuntimeException(sqle);
}
catch(Exception e)
{
}
finally
{
try {if (null != rs) {st = rs.getStatement();rs.close();}} catch(SQLException e1) {logger.error("isWorkDay:e1" + e1);}
try {if (null != st) {st.close();}} catch(SQLException e3) {logger.error("isWorkDay:e1" + e3);}
try {if (null != connection) {connection.close();}} catch(SQLException e2) {logger.error("isWorkDay:e1" + e2);}
}
return false;
}


问题:当执行try {if (null != connection) {connection.close();}} catch(SQLException e2) {logger.error("isWorkDay:e1" + e2);}也就是关闭connection的时候回跳转到while (rs.next())
{
return true;
}或者
while (rs.next())
{
return false;
}
为啥会跳转到前面呢?如果我定义一个boolean值 依次赋值,最后返回该boolean值则可以按正确顺序走下去,请指点下啥原因吧,迷茫啊
...全文
73 点赞 收藏 1
写回复
1 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告