[Advanced-java] java problem

swati awasthy swatiawasthy6 at gmail.com
Mon Jul 7 00:15:07 PDT 2008


i am creating a gui in java swings using jtable and jdbc..
i want that whever i make any changes to any cell in my jtable then those
changes sholud be saved to my database .my database is in ms-access..
i m using the following setValueAt
method:

it throws an exception
sql exception Syntax error

[odbc][Ms-Access driver]COUNT error


heres the code


public void setValueAt(Object value, int row, int col)
                {


    Vector rowData = (Vector)data.elementAt(row);
    Object o = dataRow.elementAt(col);

    if(o! = value)
    {

        try
        {
           /String s = "UPDATE Table2 SET " +
                       metaData.getColumnName(col+1) + "=";
            int curType = metaData.getColumnType(col+1);

            switch(curType)
            {
                case Types.CHAR:
                case Types.VARCHAR:
                case Types.LONGVARCHAR:
                case Types.DATE:
                    s += "'"+value.toString()+"'";
                    break;
                case Types.TINYINT:
                case Types.SMALLINT:
                case Types.INTEGER:
                case Types.BIGINT:
                case Types.FLOAT:
                case Types.DOUBLE:
                    s += value.toString();
                break;
                    default:
                    s += "'"+value.toString()+"'";
            }

            s += " WHERE CUSTID = " + dataRow.elementAt(0)+"";
            statement.executeUpdate(s);
            // refresh
            this.executeQuery();

        } catch(SQLException e) { System.out.println(e);}
    }
}

public boolean isCellEditable(int row, int col)
{ return (col>0); }





public int getColumnCount()

{
     return names.size();
}
public int getRowCount()
 {
    return data.size();
}

public Object getValueAt(int row, int col)

{
     Vector rowData = (Vector)data.elementAt(row);

     return rowData.elementAt(col);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /lists/advanced-java/attachments/20080707/020a529f/attachment.html 


More information about the Advanced-java mailing list