简体   繁体   English

如何在Java中将结果添加到MySQL存储过程的结果集中

[英]How to add result to resultset of a MySQL stored procedure in java

I want to add the results to the resultset and use table to display the results it's my java code 我想将结果添加到结果集中并使用表来显示结果,这是我的Java代码

while (resultSet.next()) {

            Object[] objects = {
                    resultSet.getDouble("January"),
                    resultSet.getDouble("February"), 
                    resultSet.getDouble("March"),
                    resultSet.getDouble("April"),
                    resultSet.getDouble("May"),
                    resultSet.getDouble("June"), 
                    resultSet.getDouble("July"),
                    resultSet.getDouble("August"), 
                    resultSet.getDouble("September"),
                    resultSet.getDouble("October"), 
                    resultSet.getDouble("November"),
                    resultSet.getDouble("December"), 
                     };
            model.addRow(objects);
        }

The error shows "Column 'Janunary' not found." 错误显示“找不到列'Janunary'”。

I am sorry that I haven't earn sufficient reputation, so I write the result of stored procedure as follows. 对不起,我还没有赢得足够的声誉,所以我将存储过程的结果编写如下。

categoryid  January   February....

1      3000      5000      (double)....

The Query code: 查询代码:

CallableStatement callableStatement = connection.prepareCall(sql);
        if (cobAccount.getSelectedIndex() != 0) {
            String accountid = cobAccount.getSelectedItem().toString()
                    .substring(0, 1);
            callableStatement.setString(1, accountid);
        } else {
            callableStatement.setString(1, "0");
        }
        if (cobYear.getSelectedIndex() != 0) {
            String year = cobYear.getSelectedItem().toString();
            callableStatement.setString(2, year);
        } else {
            callableStatement.setString(2, "0");
        }
        if (cobMember.getSelectedIndex() != 0) {
            String memberid = cobMember.getSelectedItem().toString()
                    .substring(0, 1);
            callableStatement.setString(3, memberid);
        } else {
            callableStatement.setString(3, "0");
        }
        if (!"".equals(txtMinmoney.getText())) {
            double minMoney = Double.valueOf(txtMaxmoney.getText());
            callableStatement.setDouble(4, minMoney);
        } else {
            callableStatement.setDouble(4, '0');
        }
        if (!"".equals(txtMaxmoney.getText())) {
            double maxMoney = Double.valueOf(txtMaxmoney.getText());
            callableStatement.setDouble(5, maxMoney);
        } else {
            callableStatement.setDouble(5, '0');
        }

Make sure the string you pass for the getDouble function are the actual names of your SQL columns. 确保为getDouble函数传递的字符串是SQL列的实际名称。 For example, Janunary does not seem to be spelled correctly. 例如, Janunary的拼写似乎不正确。

you skip January with your resultSet.next() no? 您用resultSet.next()跳过一月份吗?

maybe do resultSet.hasNext() or equivelant and resultSet.next() at the end of your loop? 也许在循环结束时使用resultSet.hasNext()或等价于resultSet.next()

It looks like there isn't a column named January. 似乎没有名为January的列。 Is there a column named "Month" with a value of Jan/Feb/etc? 是否有一个名为“ Month”的列,其值为Jan / Feb / etc? If you could post the table definition and query, troubleshooting would be easier. 如果您可以发布表定义和查询,则故障排除将更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM