Bonjour,

Un petit stress avec la surcharge de la méthode getValueAt de la classe AbstractTableModel,

Je crois avoir plus ou moins cerné le problème, la ligne me renvoyant l'erreur est celle ou j'essai de récupérer le contenu de la cellule avec getObject(col+1), l'origine de mes malheurs est la possibilité d'avoir des valeurs null, qui apparement ne plaisent pas trop...

J'ai essayé de corriger le pas avec un test de valeur null, mais je suppose que c'est la méthode getObject qui jette l'exception, donc si je ne me plante pas j'aurais beau faire tous les tests possible et imaginable l'exception sera lancé avant tout test...

J'ai un peu écumer google, pas de solution miracle, j'ai trouvé des trucs ou il parlait de récupérer le type avec un getClass j'ai eu beau retourner le truc dans tous les sens ça ne change rien...

Autrement tout s'affiche correctement, seulement les cellules null passent pas...

Quelqu'un aurais une idée, je mets mon code a la suite, si quelqu'un a le courage de jetter un coup d'oeil :

méthode getValueAt :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
@Override
    public String getValueAt(int row, int col) {
        try{
        this.rs.absolute(row+1);
        }
        catch(Exception exc){
           String err = exc.toString();
           System.out.println("ça plante getValueAt() absolute EmployeTableModel : " + err);
           exc.printStackTrace();
           return "0";
        }
 
        try{
 
        String tmp; 
        if ( rs.getObject(col+1).equals(null))
            return "0";
        else return tmp = rs.getObject(col+1).toString();
                /*if("".equals(tmp))
            return "0";*/
 
        }
        catch(Exception exc){
           String err = exc.toString();
           System.out.println("ça plante getValueAt() getObject EmployeTableModel : " + err);
           exc.printStackTrace();
           return "0";
        }
et ma déclaration de modèle :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
 
import java.util.*;
 
/**
 *definition du modele de tableau d'affichage des employes
 * etend AbstractTableModel classe abstraite et implèmente
 * les methodes getValueAt, getColumnName, getColumnCount
 * de la classe abstraite
 * 
 * @author David Gentil
 */
public class EmployeTableModel extends AbstractTableModel {
    private ResultSet rs;
    private ResultSetMetaData rsmd;
 
    public EmployeTableModel(ResultSet rs) throws SQLException{
        this.rs = rs;
        this.rsmd =rs.getMetaData();
    }
 
    @Override
    public String getValueAt(int row, int col) {
        try{
        this.rs.absolute(row+1);
        }
        catch(Exception exc){
           String err = exc.toString();
           System.out.println("ça plante getValueAt() absolute EmployeTableModel : " + err);
           exc.printStackTrace();
           return "0";
        }
 
        try{
 
        String tmp; 
        if ( rs.getObject(col+1).equals(null))
            return "0";
        else return tmp = rs.getObject(col+1).toString();
                /*if("".equals(tmp))
            return "0";*/
 
        }
        catch(Exception exc){
           String err = exc.toString();
           System.out.println("ça plante getValueAt() getObject EmployeTableModel : " + err);
           exc.printStackTrace();
           return "0";
        }
 
 
    }
 
 
    @Override
    public String getColumnName(int col){
        try{
            return (this.rsmd.getColumnName(col+1).toString()) ;
        }
        catch (Exception exc){
            String err = exc.toString();
            System.out.println("ça plante getColumnName() EmployeTableModel: " + err);
            exc.printStackTrace();
            return "0";
        }
    }
    @Override
    public int getColumnCount(){
        try{
            return this.rsmd.getColumnCount();
        }
        catch(Exception exc){
            String err = exc.toString();
            System.out.println(" ça plante again getColumnCount() EmployeTableModel :" + err);
            exc.printStackTrace();
            return 0;
        }
    }
    @Override
    public int getRowCount(){
        try{
        this.rs.last();
        return this.rs.getRow();            
        }
        catch (Exception exc){
            String err = exc.toString();
            System.out.println(" ça plante getRowCount() EmployeTableModel "+err);
            exc.printStackTrace();
            return 0;
        }
    }
    @Override
    public boolean isCellEditable(int row, int col){
        if( col == 0 )
            return false;
        else return true;
    }
 
 
}