/*
* 将表格里的修改内容,全部复制到数据库里面
*/
table.getCellEditor().stopCellEditing(); //先结束单元格的编辑
Vector <Object> v_1 = new Vector<Object>();
int k = table.getRowCount();
for(int a=0; a<k; a++)
for(int b=0; b<6; b++)
v_1.add(tableModel.getValueAt(a, b));
int n=0; //定义变量n判断受到影响的数据表行数
Iterator<Object> its = v_1.iterator();
while(its.hasNext()){
Connection conn = null;
PreparedStatement preStat = null;
try{
conn = com.dao.DBUtils.getConnection();
String sql = "insert into 客房信息表 values ( ? , ? , ? , ? , ? , ? )";
preStat = conn.prepareStatement(sql);
preStat.setString(1, (String) its.next());
preStat.setString(2, (String) its.next());
preStat.setString(5, (String) its.next());
preStat.setInt(4, (int) its.next());
preStat.setInt(3, (int)its.next());
preStat.setString(6, (String) its.next());
preStat.executeUpdate();
n=n+1;
tableModel.removeRow(0); //操作完成后,删除表格中的数据
}catch(Exception e1){
e1.printStackTrace();
}finally{
DBUtils.close(null, preStat, conn);
}
}
描述:上面红色行出错。
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at com.interFrame.KFBJInternalFrame$4.actionPerformed(KFBJInternalFrame.java:419)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
在线等答案、、、谢谢!
v_1.add(tableModel.getValueAt(a, b).toString);
preStat.setInt(4, Integer.valueOf(its.next()).intValue());
很明显,字符串不能转化为数字。
no!等了会儿没人帮助,已自己解决,哈哈、、、