A few points:
• Class names should begin with an uppercase character. Following the Java coding conventions is a must considering you are developing enterprise applications using J2EE which itself needs you to follow rigorous coding practices.
• Comments in java begin with // or /* and not # as in Python.
• By returning an array you lose the flexibility provided by collections API and needlessly end up creating a copy of the data in the List, a bad thing. Looks like a case of premature optimization.
But if you still need it, try something like:
public TestClass[] dbFunction()
{
int size = -1;
TestClass arr[] = null;
List aList = new ArrayList<TestClass>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try
{
ps = conn.prepareStatement("select * from testTable");
rs = ps.executeQuery();
while(rs.next())
{
aList.add(new TestClass(rs.getString(1)));
}
size = aList.size();
if(size > 0)
{
arr = new TestClass[size];
aList.toArray(arr);
}
}
catch(SQLException e)
{
//do some exception handling
}
finally
{
//close everthing, general cleanup
return(arr);
}
}