Problem with Return Value

Hello:

I抦 new to Java/JSP/Struts development.

In an application I抦 working on, I have a requirement to construct a JSP to display info about team members as line items. But I would not know the member count until I query the DB (which is done by a standalone method 揼etMembers?and the code is in try-catch-finally blocks).

In 揼etMembers?I have the code as?br>

{

try

{

匘B connection & ResultSet code here?br>

匓ased on record count匨ember[] mbr = new Member[recCount]

While(ResultSet.next())

{

Mbr[ResultSet.getRow()].setMbrFName = ResultSet.getString(揊NAME?;

}

Catch()

Finally()

Return mbr;

}

So, the problem is, I抦 getting an error msg. saying the return variable is not declared anywhere, which is probably due to 搈br?being inside the 搕ry?block. But if I want to declare it outside the block as Member[] mbr = new Member();, I get an error saying I have to include the array size which at this point I would not know.

Are there any suggestions as to how I can return 搈br?without any errors?

Thanks and any input is greatly appreciated.

[1162 byte] By [chennaia] at [2007-10-2 10:12:57]
# 1

int[] array = null;

try{

array = new int[10];

} catch(Exception e){

}

return array;

You don't have to assign an instance to a variable immediately.

gimbal2a at 2007-7-13 1:35:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Declare the mbr object outside the try-catch block and then instantiate it within the try-catch.

Member[] mbr = null;

try{

mbr = new Member[recCount];

}catch(Exception e){

// handle error

}finally{

return mbr;

}

-S

slenzia at 2007-7-13 1:35:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
****, you beat me!
slenzia at 2007-7-13 1:35:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thanks both gimbal2 and slenzi for your replies. Have a great day.
chennaia at 2007-7-13 1:35:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...