jtable中的JCheckbox在mysql数据库中存储值

时间:2013-04-06 21:32:47

标签: java mysql swing jtable jcheckbox

您好我有这个问题:我想将复选框值存储在mysql数据库中,并使用以下代码从该数据库加载它的值:

String [][]Database = new String[500][10];
     String query=null;
     PreparedStatement pstmt=null;
     ResultSet res=null;  
     int i=0;
       query= "SELECT * FROM dipendenti  ";
       try {
           pstmt=Connessioni.connection.con.prepareStatement(query);
           res=pstmt.executeQuery();

           while(res.next()){
               Database[i][0]=res.getString("nome");
               Database[i][1]=res.getString("codice");
               Database[i][2]=res.getString("livello");
               Database[i][3]=res.getString("cc");
               Database[i][4]=res.getString("ca");
               Database[i][5]=res.getString("successo");
               System.out.println("OK");
               i++;
           }
       } catch (SQLException ex) {
           Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
       }

    String [] tool = {"Nome","Codice","Livello","Data_CC","Data_CA","SUCCESSO"};

    DefaultTableModel m = new DefaultTableModel(null,tool){
     @Override
     public boolean isCellEditable(int row, int column) {      
        return false;       
     }

     public Class getColumnClass(int col) {  
        if (col == 5) {  
           return Boolean.class;  
        }  
        return getValueAt(0, col).getClass();  
     } 
};

while(i>0){

  m.addRow(Database[i-1]); //-1 perchè i parte da n e non da n-1
  i--;
}
brooker = new JTable(m);

但是当我从数据库中加载程序时,程序会滞后并变得全黑,我得到了这个例外:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at agenda_brooker.PaginaPrincipale$1.getColumnClass(PaginaPrincipale.java:95)
    at javax.swing.JTable.getColumnClass(JTable.java:2701)
    at javax.swing.JTable.getCellRenderer(JTable.java:5686)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2113)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2016)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
    at javax.swing.JComponent.paintComponent(JComponent.java:778)
    at javax.swing.JComponent.paint(JComponent.java:1054)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
    at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

0 个答案:

没有答案