Hi All,

Really appreciate your help!!!
I am new to java and this is my new project in java.
for my application am trying to get DB results by calling a oracle procedure through JDBC.i was able to do that and was getting results back to the DAO class.am setting those values into bean with setter method,but the problem here is when am trying to retrieve those values in other class using getter method am getting only one value.I can get the values using getter method of bean in the same class that to in the same while loop.
Please help me with this..

public List getTimePeriodDD()throws Exception{
        ArrayList weekDD = new ArrayList();
        DBConnection dbcon = new DBConnection();
        CallableStatement cstmt = null;
        LoginForm form = new LoginForm();
        ResultSet rs3 = null;
        String userId = "";
        String periodType = "";
        String periodName = "";
        String process = "";
        int periodValue = 1;
        String query = Queries.getQuery();//procedure call
        try{
             Connection conn = dbcon.getConnection();
            cstmt = conn.prepareCall(query);
            System.out.println(query);
            int j=0;
            cstmt.registerOutParameter(++j, OracleTypes.INTEGER);
            cstmt.setString(++j, userId);
            cstmt.setString(++j, periodType);
            cstmt.setString(++j, periodName);
            cstmt.registerOutParameter(j, OracleTypes.INTEGER);
            cstmt.setString(++j, process);
            cstmt.setInt(++j, periodValue);
            cstmt.registerOutParameter(++j,OracleTypes.CURSOR);
            cstmt.registerOutParameter(++j,OracleTypes.CURSOR);
            cstmt.registerOutParameter(++j,OracleTypes.CURSOR);
            cstmt.registerOutParameter(++j,OracleTypes.CURSOR);
            cstmt.registerOutParameter(++j,OracleTypes.CURSOR);
            cstmt.registerOutParameter(++j,Types.VARCHAR);
            cstmt.registerOutParameter(++j,Types.VARCHAR);
            cstmt.registerOutParameter(++j,Types.VARCHAR);
            cstmt.registerOutParameter(++j,Types.VARCHAR);
            cstmt.registerOutParameter(++j,Types.INTEGER);
            cstmt.registerOutParameter(++j,Types.VARCHAR);

            cstmt.execute();
            rs3 = (ResultSet)cstmt.getObject(11);
            int indx = 0;
            while(rs3.next()){
                form.setStartWeek(rs3.getString(1));
                weekDD.add(form);
            System.out.println(form.getStartWeek());//am getting complete list of results

            }
             System.out.println(form.getStartWeek());//here am getting only one value

    }
        catch(Exception e){
            e.printStackTrace();
        }
        return weekDD;
    }

Recommended Answers

All 5 Replies

The normal convention is that a set... method sets a single value, so when you call it repeatedly in your loop you are overwriting the the value you just set. There is only one value to get..., which will be the last one you set.
If a bean has an attribute that takes multiple values you usually see an add... method, not a set..., and the get... method takes a parameter to identify which value you are getting.

Hi James,

Thank you for the response.
i was able to get the list of values for another query.(the query is a stright forward one and am passing one parameter) but while calling the proc am not able to get the complete list of results back with getter method.

Here is the for loop through which am getting the results for other query,

List al = dao.getTimePeriodDD();
            for(int i=0;i<al.size();i++){
                LoginForm form = (LoginForm)al.get(i);
                System.out.println(form.getStartWeek());

Its up to the person who designed the bean to decide which attributes are single values and which are lists, and implement the accessors accordingly. Unless you can change or subclass the bean you'll probably just have to work around that.

you could store the results you get into an array of instances of your bean

Thanks stultuske,

It worked!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.