我做了个课设目的是实现增删改查,其余没问题,但是在修改时出了点问题,老是提示 没有为参数号2设置值,求大神指导,最好能给出代码实现
这个是我做的界面,增删改用了菜单
然后为修改按钮注册监听器,然后进行修改,下面的修改按钮(b2)的监听器代码(用的是SQL 2008)
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int i,j,index=0,count ;
db dbcon=new db();
if(table.getCellEditor()!=null)
{
table.getCellEditor().stopCellEditing();
}
try
{
String sql="update [card] set cardIdcardPwd=?,cardBalance=?,openDate=?,openAmount=? where cardId=?";
PreparedStatement presta=dbcon.PreparedStatement(sql);
count=tablemodel.getEditedIndex().size();
if(count >0)
{
for( i=0;i<count;i++)
for(j=1;j<table.getColumnCount();j++)
{
index=tablemodel.getEditedIndex().get(i);
presta.setString(j, table.getValueAt(index,j).toString());
presta.setString(j, table.getValueAt(index, 0).toString());
presta.addBatch();
}
}
presta.executeBatch();
} catch (SQLException sqle) {
System.out.println(sqle.toString());
}
}
});