0
SELECT false as "Select" from Table_Name

The SQL run in derby I got this output:

The SQL run in MYSQL I got this output:

I want to create a JTable with a check box column by using the ResultSet.

It is workable when i use derby, my JTable got a column with check box.

But when I use MYSQL, my JTable got a column with 0.

The problem is found in Which MySQL data type to use for storing boolean values

So now I'm thinking of:

  1. Is it possible I can configure MYSQL until it can return check box like derby does?
  2. Is there a function in MYSQL that can return boolean data type true/false? Not other data types.
  3. Is it possible I can alter the ResultSet to get the check box?

My final objective is to create a JTable with a check box column as the first column and filled with data SELECT from database. Everyone wants the easy way.

Currently I'm using this method Using Rob Camick's ListTableModel, but JTable doesnt show up

//ListTableModel model = ListTableModel.createModelFromResultSet(rs); 
model = ListTableModel.createModelFromResultSet(rs); 
Community
  • 1
  • 1
SoYuJe
  • 105
  • 11
  • `JTable`, by default, selects the appropriate cell renderer based on the class type of the value of the column. Using a `DefaultTableModel`, for example, will result in it using the columns `class` type directly (`value.getClass()`), which may not return `Boolean`. One solution is to set the column renderer directly, but you will need to be able to return a `true`/`false` value for the column value in order for it to work. – MadProgrammer Nov 30 '15 at 21:24
  • Have a look at [How to Use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) and [Using Custom Renderers](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer) – MadProgrammer Nov 30 '15 at 21:24

1 Answers1

0

Thanks MadProgrammer,

The custom renderer really works, and I found a suitable custom column renderer.

CheckBoxTableCellRenderer.java

My final objective is achieved, to create a JTable with a check box column as the first column and filled with data SELECT from database. Everyone wants the easy way.

SoYuJe
  • 105
  • 11