I need help on this, im not getting how to go about this... ok, let me explain where im stuck,
i have a class, and its structure goes like this(i will show a some kind of replica of original class, so that you guys can easily follow my question),
public class testClass{
String name = "";
ArrayList arrList = new ArrayList();
public viod setName(String string)
{
name = string;
}
public String getName(String string)
{
return name;
}
}
This class i use as a helper class in one of the EJB(Stateless Session Bean), and i have created a webservice of it.
I have another class(say dbClass) which handles all database queries. I have defined a function(say, dbFunction()) in this class(dbClass) which returns
Array of the above testClass
, for eg: testClass[] dbFunction(){...}
. The function, dbFunction()
, should go like this,
i will write a psuedo code of this,
public testClass[] dbFunction(){
ArrayList a =new ArrayList();
PreparedStatement ps = null;
ResultSet rs = null;
try{
ps = conn.prepareStatement("select * from testTable");
rs = ps.executeQuery();
if (!rs.next()){
# i have done this so far
a.add(new testClass());
# if there is no records in the result set then, what should i return...?
}
else{
while(rs.next())
{
# create an object of testClass, set the properties of it usig setter methods..
# and add that objet to array list, a
}
}
}catch(SQLException)
{...}
testClass[] res = new testClass[ a.size() ];
a.toArray(res);
return res;
}
but some how i need function to return some meaning full, saying the array of testClass is empty... but i get exception, if there is no records in the resultset. The exception is my own defined exception(say, testException).
But function works fine when i have record set in the result set.
Please let me know,
- where im doing wrong
- how i should go with this problem ...
thanks in advance.
kath.