怎么得到JTable中的值,并把它们添加到数据库中?
JTable中的数据有多行,我用了一个Vector,
Vector<String> vector = new Vector<String>();
for(int i=0;i<jTable.getRowCount();i++){
str = jTable.getValueAt(i,0);
vector.add(str);
}
然后通过sql语句将vector的值添加到数据库中,但数据库中显示的却是JTable中最后一行的值。这个该怎么修改啊?

解决方案 »

  1.   

    Vector<String> vector = new Vector<String>();
    for(int i=0;i<jTable.getRowCount();i++){
    str = jTable.getValueAt(i,0);
    vector.add(str);
    }0是只取了第一列
    按照你的写
    Vector vectorRow = new Vector();
    Vector vectorTable = new Vector();
    int rowCount = table.getModel().getRowCount();
    int columnCount = table.getModel().getColumnCount(); for(int i = 0; i < rowCount; i++)
    {
        for(int j = 0; j < columnCount; j++)
        {
            vectorRow.add(table.getValueAt(i,j));
        }
        vectorTable.add(vectorRow);
    }