简体   繁体   English

每当我尝试获取表上的值并在 `setString` 上使用它时,我都会收到 indexOutOfBoundsException

[英]I am getting indexOutOfBoundsException whenever I try to get the value on my table and use it on `setString`

I cant get the data on my table when using setString() method it says that indexOutOfBoundsException使用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 already fixed it, camickr is right.我已经修好了,camickr 是对的。 Whenever I select a row on a table, the selected row will reset.每当我在表格上选择一行时,选定的行将重置。 And that is the cause of the error.这就是错误的原因。 Thank you and sorry because im new to programming and using this site😅谢谢你,对不起,因为我是编程和使用这个网站的新手😅

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

相关问题 为什么我会收到 IndexOutOfBoundsException? - Why am I getting IndexOutOfBoundsException? 当我尝试从Jframe中的表中获取字符串时,为什么会出现错误? - Why am I getting an error when I try to get a string from my table in a Jframe? 为什么我会收到 IndexOutOfBoundsException 错误? - Why am I getting an IndexOutOfBoundsException error? 为什么我在这里收到 IndexOutOfBoundsException? - Why am i getting IndexOutOfBoundsException here? 为什么我在这里得到IndexOutOfBoundsException? - Why am I getting an IndexOutOfBoundsException here? 为什么我会收到此 IndexOutOfBoundsException 错误? - Why am I getting this IndexOutOfBoundsException error? 我的arraylist出现IndexOutOfBoundsException,我在做什么错? - I'm getting an IndexOutOfBoundsException with my arraylist, what am I doing wrong? 从对话框调用活动方法时,为什么会出现 IndexOutOfBoundsException 错误? - Why am I getting an IndexOutOfBoundsException error when calling an activity method from my dialog? 为什么在尝试将数据放入 JavaFX 散点图中时出现 IndexOutOfBoundsException? - Why am I getting an IndexOutOfBoundsException when trying to put data in my JavaFX ScatterChart? 为什么使用try catch时会出现错误 - Why i am getting Error if i use try catch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM