These are the exceptions.我们创建了一个jtable,数据通过添加按钮添加到表中。它通过提交按钮发送到数据库。但是单击提交按钮时会生成异常。任何人都可以告诉我代码出错的地方??
<div class="main">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box">4</div>
<div class="box">5</div>
</div>
答案 0 :(得分:1)
使用PreparedStatement的序列看起来有点奇怪,你不需要在更新它时提供一个值,你做了两件事,你把它添加到db然后再添加到批处理。
试试这样:
for(int row = 0; row<count; row++)
{
String roll = (String)table.getValueAt(row, 0);
String name = (String)table.getValueAt(row, 1);
String MARKS1 = (String)tableModel.getValueAt(row, 2);
String MARKS2 = (String)table.getValueAt(row, 3);
String marksinwords = (String)table.getValueAt(row, 4);
pst.setString(1, roll);;
pst.setString(2, name);
pst.setString(3,MARKS1 );
pst.setString(4,MARKS2 );
pst.setString(5, marksinwords);
pst.addBatch();
}
pst.executeBatch();
conn.commit();