当使用 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();
最佳答案
我已经修好了,camickr 是对的。每当我在表格中选择一行时,所选行将重置。这就是错误的原因。谢谢你,对不起,因为我是编程和使用这个网站的新手😂
关于java - 每当我尝试获取表上的值并在 `setString` 上使用它时,我都会收到 indexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59338499/