the right way of programming
If you see the example belong, is that the right way to program?
What do I mean exactly. Can I give a db-connection as parameter to another method? Can I give a list to another void methode and fill it there?
public List getTestList(){
Connection dbconn = session.connection();
ArrayList list =new ArrayList();
try{
String sql ="some select sql statement";
PreparedStatement pstmt = dbconn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery(sql);
while (rs.next()){
getSubTestList(rs, list, dbconn);
}
pstmt.close();
rs.close();
}catch (SQLException ex){
log.error("Blablabla");
log.error(ex);
}
return list;
}
privatevoid getSubTestList(ResultSet rs, ArrayList list, Connection dbconn){
String sql2 =null;
PreparedStatement pstmt2 =null;
ResultSet rs2 =null;
try{
String test = rs.getString(1);
String test2 =null;
while (test !=null){
sql2 ="some other select sql statement";
pstmt2 = dbconn.prepareStatement(sql2);
rs2 = pstmt2.executeQuery(sql2);
while (rs2.next()){
test2 = rs2.getString(1);
list.add(test2);
}
}
rs2.close();
pstmt2.close();
}catch (SQLException ex){
log.error("Blablabla");
log.error(ex);
}
}

