How to set a TableColumn-type?!? [message #446708] |
Wed, 01 December 2004 04:20  |
Eclipse User |
|
|
|
Originally posted by: melko.gmx.at
hello!
I have a problem: I select items from a database to a table and it works
fine.
I do it on this way:
ResultSet resSet = stmt.executeQuery(text);
ResultSetMetaData result = resSet.getMetaData();
int col = result.getColumnCount();
TableColumn[] tableColumn = new TableColumn[col];
for(int i=1; i<=col;i++){
tableColumn[i-1] = new TableColumn(table, SWT.LEFT, i-1);
tableColumn[i-1].setText(result.getColumnName(i));
And I get the results in the table and so on. But I want to set the Column
type to DATE or CHAR or INTEGER depending on the
result.getColumnType(i)!?!?! so I can, if there is a DATE-Column in the
databse show it right!?
Example:
In the DB there is a Column "Birthday" DATE and it should show only the
Date without time, but it shows follow: 1983-05-01 00:00:00.000000
or other example:
"user_jahr" is a DECIMAL and it should show 25 but I get
25.0000000000000000
Is it possible to do something there or not?!
Thank you for your help!!
Nice greetings from austria!
Have a nice day
|
|
|
Re: How to set a TableColumn-type?!? [message #446744 is a reply to message #446708] |
Thu, 02 December 2004 04:31  |
Eclipse User |
|
|
|
There are no column types available in SWT. You have to cast/convert the
datatypes from the db to whatever format you want to display.
For example:
tableItem.setText(DateFormat.getDateInstance().format(myDate ));
- will display the date "1983-05-01 00:00:00.000000" like this: "01-05-1983"
(dependent of your locale).
If I was you, I would consider a single row in my table as an object, so I'd
create a class containing all the different columns as properties. In this
way you wouldn't have to think about datatypes in the gui part of your
project.
"melko" <melko@gmx.at> wrote in message news:cok2cj$v1m$1@www.eclipse.org...
> hello!
>
> I have a problem: I select items from a database to a table and it works
> fine.
> I do it on this way:
>
> ResultSet resSet = stmt.executeQuery(text);
> ResultSetMetaData result = resSet.getMetaData();
> int col = result.getColumnCount();
> TableColumn[] tableColumn = new TableColumn[col]; for(int i=1;
> i<=col;i++){
> tableColumn[i-1] = new TableColumn(table, SWT.LEFT, i-1);
> tableColumn[i-1].setText(result.getColumnName(i));
>
> And I get the results in the table and so on. But I want to set the Column
> type to DATE or CHAR or INTEGER depending on the
> result.getColumnType(i)!?!?! so I can, if there is a DATE-Column in the
> databse show it right!?
> Example:
> In the DB there is a Column "Birthday" DATE and it should show only the
> Date without time, but it shows follow: 1983-05-01 00:00:00.000000
> or other example:
>
> "user_jahr" is a DECIMAL and it should show 25 but I get
> 25.0000000000000000
>
> Is it possible to do something there or not?!
> Thank you for your help!!
>
> Nice greetings from austria!
>
> Have a nice day
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03330 seconds