Récupérer donnée Boolean sur une table
salut
je veux bien récupérer les données d'une table avec un champ booléen mais ça marche pas
la base de donnée oracle
voila comment j'ai crée la table
Code:
1 2 3 4 5 6
|
CREATE TABLE PAIE
(
ETAT NUMBER(1) , CONSTRAINT CHK_PAIE_ETAT_BOOLEAN
CHECK (ETAT IN (0,1))
); |
et
le code pour récupérer les donnée dans la table
Code:
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
|
try {
Connection connection = null;
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
String serverName = "10.133.0.25";
String portNumber = "1521";
String sid = "fin";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid;
String username = "DEVRTO";
String password = "DEVRTO";
connection = DriverManager.getConnection(url, username, password);
Statement instruction = connection.createStatement();
String sql1 =" select paie.* from paie ";
ResultSet resultat = instruction.executeQuery(sql1);
ResultSetMetaData md = resultat .getMetaData();
columns = md.getColumnCount();
for (int id = 1; id < columns+1; id++) {
columnNames.addElement(md.getColumnName(id));
}
int size=0;
while (resultat .next()) {
Vector row = new Vector(columns);
for (int j = 1; j <= columns; j++) {
Object v = resultat .getObject(j);
row.addElement(v);
}
data.addElement(row);
}
tableModel = new DefaultTableModel(data, columnNames) {
public Class getColumnClass(int columnIndex) {
return (columnIndex == 1) ? Boolean.class : String.class;
}
};
jTable = new JTable(tableModel) ;
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable.getColumnModel().getColumn(0).setPreferredWidth(80);
jTable.getColumnModel().getColumn(1).setPreferredWidth(200);
jTable.setBackground(Color.orange);
jTable.setIntercellSpacing(new Dimension(2, 1));
jTable.setRowHeight(24);
jTable.setLocation(new Point(2, 0));
jTable.setFont(new Font("Arial", Font.PLAIN, 14));
jTable.setVisible(true);
jScrollPane.setBounds(new Rectangle(90, 130, 643, 389));
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane.setViewportView( jTable);
}catch (Exception ex) {
ex.printStackTrace() ;
} |
Code:
1 2
|
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Boolean |
problème avec cette partie
Code:
1 2 3 4
|
public Class getColumnClass(int columnIndex) {
return (columnIndex == 1) ? Boolean.class : String.class;
} |
merci