update data from jTable to database -null pointer

2019-08-30 03:04发布

问题:

Im trying to read values from my jTable1

 private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
   int colum=jTable1.getSelectedColumn();
   int row=jTable1.getSelectedRow();
   System.out.println("row of selected is "+row+"col is "+colum);

   final String remark1 = (String) jTable1.getValueAt(row, 8);
    final String remark2 = (String) jTable1.getValueAt(row, 9);
    final String invoiceno = (String) jTable1.getValueAt(row, 11);
    final String id=(String) jTable1.getValueAt(row, 12);
   System.out.println(id + "id");
try{
    Transaction t = new Transaction(s) { 
       public Object transact() throws BasicException {

          System.out.println("try loop for update");
            SentenceExec followinsert = new PreparedSentence(s
                   , "UPDATE FOLLOWUP SET REMARK1= ?, REMARK2=?, INVOICENO=? WHERE ID= ?"
                   , SerializerWriteParams.INSTANCE);
                    followinsert.exec(new DataParams() { public void writeValues() throws BasicException {
                    System.out.println("executing command");
                       setString(1, remark1);
                       setString(2, remark2);
                       setString(3, invoiceno);
                       setString(2, id);
                     //System.out.println(" after update line");
                   }});
                return null;
            }

    };

        t.execute();    //im getting null pointer exception here :(
    }
    catch (BasicException ex) {
        Logger.getLogger(FollowUp.class.getName()).log(Level.SEVERE, null, ex);
    }
}

i get this error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.openbravo.data.loader.Transaction.execute(Transaction.java:42)
at com.openbravo.pos.followup.FollowUp.jcmdOKActionPerformed(FollowUp.java:679)
at com.openbravo.pos.followup.FollowUp.access$300(FollowUp.java:66)
at com.openbravo.pos.followup.FollowUp$5.actionPerformed(FollowUp.java:193)

Transaction.java is

public abstract class Transaction<T> {

private Session s;

/** Creates a new instance of Transaction */
public Transaction(Session s) {
    this.s = s;
}

public final T execute() throws BasicException {

    if (s.isTransaction()) {
        return transact();
    } else {
        try {
            try {    
                s.begin();
                T result = transact();
                s.commit();
                return result;
            } catch (BasicException e) {
                s.rollback();
                throw e;
            }
        } catch (SQLException eSQL) {
            throw new BasicException("Transaction error", eSQL);
        }
    }
}

protected abstract T transact() throws BasicException;
}