【问题标题】:I am getting indexOutOfBoundsException whenever I try to get the value on my table and use it on `setString`每当我尝试获取表上的值并在`setString`上使用它时,我都会收到 indexOutOfBoundsException
【发布时间】:2020-04-07 20:19:13
【问题描述】:

使用setString() 方法时,我无法在我的表上获取数据,它说 indexOutOfBoundsException

String upd = "update sinfo set sname = ?, course = ?, section = ?, dob = ?, address = ? where sid = ?";
String sc = course.getSelectedItem().toString();
TableModel model = sTable.getModel();
int i = sTable.getSelectedRow();

pst = conn.prepareStatement(upd);

pst.setString(1, sn.getText());
pst.setString(2, sc);
pst.setString(3, ss.getText());
pst.setString(4, db.getText());
pst.setString(5, ad.getText());
pst.setString(6, model.getValueAt(i,0).toString()); //I get the error here saying indexOutOfBoundsException: -1

pst.executeUpdate();

【问题讨论】:

  • 发布实际的错误声明和导致问题的行。也许问题出在“i”变量上,因为您没有选定的行?
  • 我已经选择了一行,然后当我尝试执行该功能时,我得到 pst.setString(6, model.getValueAt(i,0).toString()); 上的错误;跨度>

标签: java mysql netbeans


【解决方案1】:

我已经修好了,camickr 是对的。每当我在表格上选择一行时,所选行将重置。这就是错误的原因。谢谢和抱歉,因为我是编程和使用这个网站的新手?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2022-09-28
    • 2019-12-23
    • 1970-01-01
    相关资源
    最近更新 更多