当前位置: 动力学知识库 > 问答 > 编程问答 >

database - 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

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."

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. For example, Janunary does not seem to be spelled correctly.

网友答案:

you skip January with your resultSet.next() no?

maybe do resultSet.hasNext() or equivelant and resultSet.next() at the end of your loop?

网友答案:

It looks like there isn't a column named January. Is there a column named "Month" with a value of Jan/Feb/etc? If you could post the table definition and query, troubleshooting would be easier.

分享给朋友:
您可能感兴趣的文章:
随机阅读: