Plumel
Plumel

Reputation: 45

Weird bit values from MySQL table

Having inserted a MySQL table values to a JTable and previewing this JTable, I noticed that the "BIT" column is returning a "1" as a strange box which I am unable to paste into here, and it returns 0's as blanks. I'll leave a screenshot of the bit error display:

enter image description here

Upvotes: 1

Views: 300

Answers (2)

trashgod
trashgod

Reputation: 205785

By default, JTable renders TableModel values of type Boolean using a JCheckBox. You can make the cell editable by returning true for that column in your model's implementation of isCellEditable(), as shown here.

Alternatively, you can

  • Return your preferred type for that column in your model's implementation of getColumnClass(), as shown here.

  • Use a custom renderer, as shown here.

Upvotes: 1

Shadow
Shadow

Reputation: 34231

BIT columns store bits as binary data, not as "1" or "0" (string with the character 1 or 0), you need to convert the bit value to string using export_set() function. If your field is defined as BIT(M) (M is the length of the bit field), then

select export_set(field_name, '1','0','',M) from yourtable

query will return the bit field's value in a string representation, with continuous 1s and 0s.

Upvotes: 1

Related Questions