2013-09-06 3 views
1

Вот мой полный код ...Дисплей ResultSet в пользовательских JTable

Когда я запускаю это и нажмите кнопку его показ nullpointer exception в результирующем

package com.openbravo.pos.followup; 

/** 
* 
* @author manideep 
*/ 
    public class FollowUp extends javax.swing.JPanel implements JPanelView, BeanFactoryApp { 
    private AppView m_App; 
    protected DataLogicCustomers dlCustomers; 
    // CustomerInfo customer; 
    private AppConfig conf; 
    // private ListProvider lpr 
    private DefaultTableModel modelx, model; 
    protected DataLogicFollowUp dlFollowUp; 
    /** 
    * Creates new form FollowUp 
    */ 
    public FollowUp() { 
     initComponents(); 
     String[] args = {}; 
     conf = new AppConfig(args); 
     conf.load(); 
     jLabel3.setText(""); 
    } 
    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    private void initComponents() { 

     jPanel1 = new javax.swing.JPanel(); 
     jLabel1 = new javax.swing.JLabel(); 
     jTextField1 = new javax.swing.JTextField(); 
     jButton1 = new javax.swing.JButton(); 
     jLabel3 = new javax.swing.JLabel(); 
     jButton3 = new javax.swing.JButton(); 
     jButton4 = new javax.swing.JButton(); 
     m_jTicketId3 = new javax.swing.JLabel(); 
     m_jTicketId1 = new javax.swing.JLabel(); 
     jScrollPane1 = new javax.swing.JScrollPane(); 
     jTable1 = new javax.swing.JTable(); 
     jcmdOK = new javax.swing.JButton(); 
     jcmdCancel = new javax.swing.JButton(); 
     jCheckBox1 = new javax.swing.JCheckBox(); 

     jLabel1.setText("Enter Date"); 

     jTextField1.setPreferredSize(new java.awt.Dimension(90, 19)); 

     jButton1.setText("Submit"); 
     jButton1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton1ActionPerformed(evt); 
      } 
     }); 

     jLabel3.setText("jLabel3"); 

     jButton3.setText("Customer"); 
     jButton3.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton3ActionPerformed(evt); 
      } 
     }); 

     jButton4.setText("Product"); 
     jButton4.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton4ActionPerformed(evt); 
      } 
     }); 

     m_jTicketId3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 
     m_jTicketId3.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4))); 
     m_jTicketId3.setOpaque(true); 
     m_jTicketId3.setPreferredSize(new java.awt.Dimension(160, 25)); 
     m_jTicketId3.setRequestFocusEnabled(false); 

     m_jTicketId1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 
     m_jTicketId1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4))); 
     m_jTicketId1.setOpaque(true); 
     m_jTicketId1.setPreferredSize(new java.awt.Dimension(160, 25)); 
     m_jTicketId1.setRequestFocusEnabled(false); 

     javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
     jPanel1.setLayout(jPanel1Layout); 
     jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addContainerGap() 
       .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addGroup(jPanel1Layout.createSequentialGroup() 
         .addComponent(jLabel1) 
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
          .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
          .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)) 
         .addGap(154, 154, 154) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
          .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) 
          .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)) 
         .addGap(18, 18, 18) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
          .addComponent(m_jTicketId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
          .addComponent(m_jTicketId3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 
        .addComponent(jLabel3)) 
       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
     ); 
     jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addGroup(jPanel1Layout.createSequentialGroup() 
         .addGap(21, 21, 21) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
          .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE) 
          .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
         .addGap(18, 18, 18) 
         .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)) 
        .addGroup(jPanel1Layout.createSequentialGroup() 
         .addGap(24, 24, 24) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
          .addComponent(jButton3) 
          .addComponent(m_jTicketId3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
          .addGroup(jPanel1Layout.createSequentialGroup() 
           .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
           .addComponent(jButton4)) 
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
           .addGap(17, 17, 17) 
           .addComponent(m_jTicketId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 
         .addGap(0, 0, Short.MAX_VALUE))) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
       .addComponent(jLabel3) 
       .addGap(24, 24, 24)) 
     ); 

     jTable1.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] { 

      }, 
      new String [] { 
       "Customer", "Phone No.", "Product", "Last sold Qty.", "Consumption", "last sale date", "Delivery Date", "Remark 1", "Remark 2", "Stock(Y/N)", "Invoice No." 
      } 
     ) { 
      Class[] types = new Class [] { 
       java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class 
      }; 
      boolean[] canEdit = new boolean [] { 
       false, false, false, false, false, false, false, true, true, true, true 
      }; 

      public Class getColumnClass(int columnIndex) { 
       return types [columnIndex]; 
      } 

      public boolean isCellEditable(int rowIndex, int columnIndex) { 
       return canEdit [columnIndex]; 
      } 
     }); 
     jTable1.getTableHeader().setReorderingAllowed(false); 
     jScrollPane1.setViewportView(jTable1); 
     jTable1.getColumnModel().getColumn(0).setResizable(false); 
     jTable1.getColumnModel().getColumn(1).setResizable(false); 
     jTable1.getColumnModel().getColumn(3).setResizable(false); 
     jTable1.getColumnModel().getColumn(4).setResizable(false); 
     jTable1.getColumnModel().getColumn(5).setResizable(false); 
     jTable1.getColumnModel().getColumn(6).setResizable(false); 
     jTable1.getColumnModel().getColumn(7).setResizable(false); 
     jTable1.getColumnModel().getColumn(7).setPreferredWidth(0); 
     jTable1.getColumnModel().getColumn(8).setResizable(false); 
     jTable1.getColumnModel().getColumn(9).setResizable(false); 
     jTable1.getColumnModel().getColumn(10).setResizable(false); 

     jcmdOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N 
     jcmdOK.setText("OK"); 
     jcmdOK.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jcmdOKActionPerformed(evt); 
      } 
     }); 

     jcmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N 
     jcmdCancel.setText("Cancel"); 
     jcmdCancel.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jcmdCancelActionPerformed(evt); 
      } 
     }); 

     jCheckBox1.setText("Select All"); 
     jCheckBox1.setMaximumSize(new java.awt.Dimension(0, 0)); 
     jCheckBox1.setPreferredSize(new java.awt.Dimension(0, 0)); 
     jCheckBox1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jCheckBox1ActionPerformed(evt); 
      } 
     }); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 
     this.setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addGap(353, 353, 353) 
       .addComponent(jcmdOK) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jcmdCancel) 
       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
        .addGroup(layout.createSequentialGroup() 
         .addContainerGap() 
         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1408, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
         .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
       .addGap(74, 74, 74)) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addGroup(layout.createSequentialGroup() 
         .addGap(8, 8, 8) 
         .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
        .addGroup(layout.createSequentialGroup() 
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE))) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(jcmdOK) 
        .addComponent(jcmdCancel)) 
       .addGap(31, 31, 31)) 
     ); 
    }// </editor-fold>//GEN-END:initComponents 

    private void getListSRLine(Element e){ 
     String customer= getAttrDataFromElement((Element)e.getElementsByTagName("customer").item(0),"identifier"); 
     String phone= getCharacterDataFromElement((Element)e.getElementsByTagName("phone").item(0)); 
     String product=getAttrDataFromElement((Element)e.getElementsByTagName("product").item(0),"identifier"); 
     String lastsoldqty=getCharacterDataFromElement((Element)e.getElementsByTagName("lastsoldqty").item(0)); 
     String consumption=getCharacterDataFromElement((Element)e.getElementsByTagName("consumption").item(0)); 
     String lastsaledate=getCharacterDataFromElement((Element)e.getElementsByTagName("lastsaledate").item(0)); 
     String deliverydate=getCharacterDataFromElement((Element)e.getElementsByTagName("deliverydate").item(0)); 
     String remark1=getCharacterDataFromElement((Element)e.getElementsByTagName("remark1").item(0)); 
     String remark2=getCharacterDataFromElement((Element)e.getElementsByTagName("remark2").item(0)); 
     String stock=getCharacterDataFromElement((Element)e.getElementsByTagName("stock").item(0)); 
     String invoiceno=getCharacterDataFromElement((Element)e.getElementsByTagName("invoiceno").item(0)); 
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); 
    model.addRow(new Object[]{customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno}); 
    //sortColumn(model, 1, true); 
    model.fireTableDataChanged(); 
    jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
    jTable1.setAutoCreateRowSorter(true); 
    jTable1.getColumnModel().getColumn(0).setPreferredWidth(150); 
    jTable1.getColumnModel().getColumn(1).setPreferredWidth(120); 
    jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); 

    jTable1.getColumnModel().getColumn(3).setPreferredWidth(50); 
    jTable1.getColumnModel().getColumn(4).setPreferredWidth(100); 

    jTable1.getColumnModel().getColumn(5).setPreferredWidth(100); 
    jTable1.getColumnModel().getColumn(6).setPreferredWidth(100); 

    jTable1.getColumnModel().getColumn(7).setPreferredWidth(100); 

    jTable1.getColumnModel().getColumn(8).setPreferredWidth(100); 
    jTable1.getColumnModel().getColumn(9).setPreferredWidth(100); 

    jTable1.getColumnModel().getColumn(10).setPreferredWidth(100); 
    jTable1.getColumnModel().getColumn(11).setPreferredWidth(0); 

    } 

    private void executeSearch() { 
     try { 

      Class.forName("org.postgresql.Driver"); 

     } catch (ClassNotFoundException e) { 

      System.out.println("Where is your PostgreSQL JDBC Driver? " 
        + "Include in your library path!"); 
      e.printStackTrace(); 
      return; 

     } 
     System.out.println("PostgreSQL JDBC Driver Registered!"); 

     Connection connection = null; 

     try { 

      connection = DriverManager.getConnection(
        "jdbc:postgresql://localhost:5432/openbravopos", "postgres", 
        "postgres"); 

     } catch (SQLException e) { 

      System.out.println("Connection Failed! Check output console"); 
      e.printStackTrace(); 
      return; 

     } 

     if (connection != null) { 
      try { 
       System.out.println("You made it, take control your database now!"); 
       int colCount; 
       String [] headers; 
       Statement stmt = null; 
     //  rs=(ResultSet) dlFollowUp.getFollowUpList(); 
     //  getFollowUplist(); 
       ResultSet rs = null; 
       rs = stmt.executeQuery("SELECT id,customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno FROM followup"); 
       java.sql.ResultSetMetaData rsmd = rs.getMetaData(); 
       int colNo = rsmd.getColumnCount(); 
        while(rs.next()){ 
         Object[] objects = new Object[colNo]; 
         for(int i=0;i<colNo;i++){ 
          objects[i]=rs.getObject(i+1); 
         } 
       model.addRow(objects); 
       } 
       jTable1.setModel(model); 

      } catch (SQLException ex) { 
       Logger.getLogger(FollowUp.class.getName()).log(Level.SEVERE, null, ex); 
      } 



     } else { 
      System.out.println("Failed to make connection!"); 
     } 
    } 

    public static String getAttrDataFromElement(Element e,String attr){ 
     return e.getAttribute(attr); 
    } 
    public static String getCharacterDataFromElement(Element e) { 
    Node child = e.getFirstChild(); 
    if (child instanceof CharacterData) { 
     CharacterData cd = (CharacterData) child; 
     return cd.getData(); 
    } 
    return ""; 
    } 
    private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdOKActionPerformed 
     // jButton1ActionPerformed(evt); 
     DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); 


     //dispose(); 

    }//GEN-LAST:event_jcmdOKActionPerformed 



    private void jcmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdCancelActionPerformed 

     dispose(); 

    }//GEN-LAST:event_jcmdCancelActionPerformed 

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed 
     // TODO add your handling code here: 
    }//GEN-LAST:event_jCheckBox1ActionPerformed 
String field=""; 
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 
     jLabel3.setText(""); 
     executeSearch(); 
     //  entity = response.getafilter(); 

    }//GEN-LAST:event_jButton1ActionPerformed 

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed 
     JCustomerFinder finder = JCustomerFinder.getCustomerFinder(this, dlCustomers); 
     finder.setVisible(true); 
     CustomerInfo custsel=finder.getSelectedCustomer(); 
     m_jTicketId3.setText(custsel.printName()); 
    }//GEN-LAST:event_jButton3ActionPerformed 

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed 
     /* // TODO add your handling code here: 
     JProductFinder finder = JProductFinder.getProductFinder(this, dlSales, m_App.getInventoryLocation(),m_App); 
     finder.setVisible(true); 
     ProductAttrInfoExt prod = finder.getSelectedProduct(); 
     m_jTicketId1.setText(prod.getName());*/ 
    }//GEN-LAST:event_jButton4ActionPerformed 

    private void dispose(){ 
     DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); 
     model.setRowCount(0); 
     jLabel3.setText(null); 
     model.fireTableDataChanged(); 
    } 

    // Variables declaration - do not modify//GEN-BEGIN:variables 
    private javax.swing.JButton jButton1; 
    private javax.swing.JButton jButton3; 
    private javax.swing.JButton jButton4; 
    private javax.swing.JCheckBox jCheckBox1; 
    private javax.swing.JLabel jLabel1; 
    private javax.swing.JLabel jLabel3; 
    private javax.swing.JPanel jPanel1; 
    private javax.swing.JScrollPane jScrollPane1; 
    private javax.swing.JTable jTable1; 
    private javax.swing.JTextField jTextField1; 
    private javax.swing.JButton jcmdCancel; 
    private javax.swing.JButton jcmdOK; 
    private javax.swing.JLabel m_jTicketId1; 
    private javax.swing.JLabel m_jTicketId3; 
    // End of variables declaration//GEN-END:variables 

    @Override 
    public String getTitle() { 
     return "Follow Up"; 
    } 

    @Override 
    public void activate() throws BasicException { 
     resetFollowUp(); 
    } 

    public void resetFollowUp(){ 
     jTextField1.setText(""); 
     m_jTicketId3.setText(""); 
     m_jTicketId1.setText(""); 

    } 

    @Override 
    public boolean deactivate() { 
     return true; 
    } 

    @Override 
    public JComponent getComponent() { 
     return this; 
    } 

    @Override 
    public void init(AppView app) throws BeanFactoryException { 

     jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
     jTable1.getColumnModel().getColumn(0).setPreferredWidth(150); 
     jTable1.getColumnModel().getColumn(1).setPreferredWidth(150); 
     jTable1.getColumnModel().getColumn(2).setPreferredWidth(250); 
     jTable1.getColumnModel().getColumn(3).setPreferredWidth(100); 
     jTable1.getColumnModel().getColumn(4).setPreferredWidth(200); 
     jTable1.getColumnModel().getColumn(5).setPreferredWidth(250); 
     jTable1.getColumnModel().getColumn(6).setPreferredWidth(250); 
     jTable1.getColumnModel().getColumn(7).setPreferredWidth(250); 
     jTable1.getColumnModel().getColumn(8).setPreferredWidth(200); 
     jTable1.getColumnModel().getColumn(9).setPreferredWidth(200); 
     jTable1.getColumnModel().getColumn(10).setPreferredWidth(100); 

     DefaultTableModel modelx = (DefaultTableModel) jTable1.getModel(); 
     for(int j=0;j< modelx.getRowCount();j++){ 

     } 
     m_App=app; 
//  setWarehouse(m_App.getWarehouseSearchKey()); 
     dlCustomers = (DataLogicCustomers) m_App.getBean("com.openbravo.pos.customers.DataLogicCustomers"); 
     } 
    @Override 
    public Object getBean() { 
     return this; 
    } 
} 

ответ

4

Вы никогда не инициализация Statement объекта ....

Statement stmt = null; // Look ma, I'm null 
//  rs=(ResultSet) dlFollowUp.getFollowUpList(); 
//  getFollowUplist(); 
ResultSet rs = null; 
// Look ma, I'm still null 
rs = stmt.executeQuery("SELECT id,customer,phone,product,lastsoldqty,consumption,lastsaledate,deliverydate,remark1,remark2,stock,invoiceno FROM followup"); 

Вам нужно создать stmt, прежде чем вы можете использовать ...

stmt = connection.createStatement(); 

Вы можете найти чтение через JDBC учебники по benifit

Проблема № 2

model Вы определяете, как переменную экземпляра в начале вашего FollowUp класса ...

private DefaultTableModel modelx, model; 

Но вы никогда не инициализируете его ни в чем.

я бы себе, основываясь на вашем коде, вы должны инициализировать его в методе executeSearch ...

// You will need to fill this out with appropriate values, 
// the number of columns in you JTable should match the 
// the number columns from your query... 
Object[] columns = new Object[]{....}; 
model = new DefaultTableModel(columns, 0); 
while(rs.next()){ 
    Object[] objects = new Object[colNo]; 
    for(int i=0;i<colNo;i++){ 
     objects[i]=rs.getObject(i+1); 
    } 
    model.addRow(objects); 
} 
+0

нормально сэр плохо попробовать, что –

+0

его не может позволить мне использовать stmt.executeQuery без инициализации STMT = ноль; –

+0

'stmt = con.createStatement()' ... – MadProgrammer

Смежные вопросы