1

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Plumel
  • 45
  • 9

2 Answers2

1

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.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • The issue with this would be that I am allowing the user to look at multiple tables. The field name of the column with the BIT values in may change throughout different tables, so I would have to change field name each time. – Plumel Sep 08 '16 at 08:09
1

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Boolean and bit data types are not the same in MySQL. Boolean is just an alias for tinyint, whereas bit data type represents a bit field. – Shadow Sep 07 '16 at 16:35
  • @Shadow: I defer to you on this; I suspect that the author is using some sort of table model adapter that elicits the default renderer in the manner illustrated. – trashgod Sep 07 '16 at 22:48
  • What I've actually got at the moment is a piece of code that loops through the rows and columns in the JTable, and if the variable holding the data is equal to the box, it changes it into a 1. I was going to do the same with the 0's, however I don't know what character is used for this (As it's just a blank space, and trying to change a space doesn't work) – Plumel Sep 08 '16 at 07:52
  • Can you determine if you're seeing a [`WHITE SQUARE`](http://www.fileformat.info/info/unicode/char/25a1/index.htm) or a `JCheckBox`? – trashgod Sep 08 '16 at 08:42