How to avoid setting variable in a try statement

前端 未结 4 1457
轻奢々
轻奢々 2020-12-22 04:45

My problem is that I have to set a variable in a try statement otherwise I get a compile error.

Later on I need to use that variable but it is now out of scope, or s

4条回答
  •  Happy的楠姐
    2020-12-22 05:21

    Thanks everyone for your help. First you helped me identify that there had to be some kind of exception being thrown. When I looked at the Tomcat console I could see it was a class not fund error for the MySQL connector. I had included that in my project, but not within the project itself - I just lazily referred to it in my lib directory, so ultimately the exception caused the problem, but using your suggestions such as if(rs != null) helped me get to the root cause.

    Initially I thought it had something to do with the variable being out of scope. Clearly that was not it.

提交回复
热议问题