views:

243

answers:

2

I'm building a application that needs to convert a ResultSet String(rs.getString(Names);) into a workable variable to populate a jTable, only one collumn, then the rest I think that I could try by doing a loop.

How could I do this?

+1  A: 

HI,I assume that you are trying to display the values in JTable, if that is the case. Why cant you get the results into a list from a Resultset and Iterate and display in the Jtable.

How you can store the data from Database to the List and same list can be sent to the Jtable

 try {

            con = ora.createConnection();
            if (con != null) {
                pstmt = con.prepareStatement(strQuery.toString());
                rs = pstmt.executeQuery();
                 while (rs.next()) {
                    khataChallanHeader.setChallanNo(Integer.valueOf(rs
                            .getInt("CHALLAN_NO")));
                    khataChallanHeader.setPropertyId(Long.valueOf(rs
                            .getLong("PROPERTY_ID")));
                    khataChallanHeader
                            .setDivisionName(rs.getString("DIV_NAME"));
                    khataChallanHeader.setCircleName(rs
                            .getString("CIRCLE_NAME"));
                    khataChallanHeader.setLayoutName(rs
                            .getString("LAYOUT_NAME"));

                     dtoList.add(khataChallanHeader);
                }

            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            pstmt.close();
            rs.close();
            ora.closeConnection(con);
        }
        // System.out.println(" the Size of the list is : " + dtoList.size());
        // return dtoList;
        return khataChallanHeader;
harigm
Yeah, but how to do this?
Nathan Campos
Let me share teh Source Code within a day, share your email I will send
harigm
eeepc904 at gmail
Nathan Campos
A: 

You create a Vector (called "data") to hold all the data.

Then you loop through the ResultSet. For every row you create a new Vector (called "row") and add the data from the ResultSet to the row Vector. Then you add the row Vector to the data Vector.

Now you create create a DefaultTableModel using the "data" Vector and another Vector containing your desired column name.

camickr