将 ResultSet 字符串转换为可用变量以填充 jTable

发布于 2024-08-30 17:06:43 字数 147 浏览 0 评论 0原文

我正在构建一个应用程序,需要将 ResultSet String(rs.getString(Names);) 转换为可用变量以填充 jTable,只有一列,然后剩下的我想我可以通过循环来尝试。

我怎么能这样做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-09-06 17:06:43

您好,我假设您正在尝试显示 JTable 中的值(如果是这种情况)。
为什么不能将结果从结果集中放入列表并迭代并显示在 Jtable 中。

如何将数据库中的数据存储到列表中,并将相同的列表发送到 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;

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;
两相知 2024-09-06 17:06:43

您创建一个 Vector(称为“数据”)来保存所有数据。

然后循环遍历 ResultSet。对于每一行,您创建一个新的向量(称为“行”)并将结果集中的数据添加到行向量中。然后将行向量添加到数据向量中。

现在,您使用“数据”向量和另一个包含所需列名称的向量创建一个 DefaultTableModel。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文