Hi Rajesh,
I was afraid Derby wouldn't have a way to set these
values on the table itself. Your code snippet gives
me an idea of how I might fake the functionality to a
caller of a wrapper class though. Thanks again for
the reply!
Jason
--- Rajesh Kartha <[EMAIL PROTECTED]> wrote:
> Hi Jason,
>
> I don't think the LABEL ON is supported in Derby.
> But to use your
> example for a table, I could achieve the same in the
> following way using
> ResultSetMetaData:
>
> Table:
> =====
> create table aTable(id INTEGER NOT NULL, name
> VARCHAR(255) NOT NULL,
> description VARCHAR(255))
>
> Select Statement:
> ============
> SELECT id as "The First Column" , name as "The
> Second Column",
> description as DESC_DETAILS FROM aTable
>
> The select method :
> =============
>
> private void selectRows() throws SQLException{
> String sql="SELECT id as \"The First
> Column\" , name as \"The
> Second Column\", description as DESC_DETAILS FROM
> aTable ";
> stmt=conn.createStatement();
> ResultSet rs=stmt.executeQuery(sql);
> ResultSetMetaData rsmd = rs.getMetaData();
> int numberCols = rsmd.getColumnCount();
> for(int i=1; i<=numberCols; i++)
> {
> System.out.print(rsmd.getColumnLabel(i)+"
> | "); //print
> the NEW Column names
> }
> System.out.println("\n");
> while(rs.next()){
> System.out.println(rs.getInt(1)+"\t |
> "+rs.getString(2)+"\t
> | "+rs.getString(3)+" ");
> }
> stmt.close();
> }
>
> The output of the above select shows:
>
> The First Column | The Second Column | DESC_DETAILS
> |
>
> 0 | NAME 0 | DESCRIPTION for 0
> 1 | NAME 1 | DESCRIPTION for 1
> 2 | NAME 2 | DESCRIPTION for 2
> 3 | NAME 3 | DESCRIPTION for 3
> 4 | NAME 4 | DESCRIPTION for 4
>
> The ResultSetMetaData returns the column names used
> in the Select query
> above. Needless to say,
> the above works per statement. Hope the above helps.
>
> -Rajesh
>
>
>
> Jason Palmatier wrote:
>
> >Hi Rajesh,
> >
> > The select isn't what I'm looking for in this
> case.
> > I'm trying to create a table and then set the
> value
> >that would be returned by the ResultSetMetaData
> call
> >getColumnLabel():
> >
> >ResultSet rs = stmt.executeQuery("SELECT COLUMN1,
> >USERNAME FROM myTable");
> >ResultSetMetaData rsmd = rs.getMetaData();
> >int numberCols = rsmd.getColumnCount();
> >for(int i=0; i<numberCols; i++)
> >{
> > System.out.println("Column " + i + " Label: "
> > + rsmd.getColumnLabel(i);
> >}
> >
> >This usually returns a String that can be used for
> the
> >human readable column heading when a table's
> contents
> >are displayed. After you execute a CREATE TABLE
> >statement you would follow it with a
> >
> >LABEL ON COLUMN myTable
> >(
> > COLUMN1 is 'The First Column',
> > COLUMN2 is 'The Second Column',
> > USERNAME is 'User Name',
> > PASSWORD is 'User Password'
> >);
> >
> >This would set the labels for the specified columns
> in
> >the table "myTable" (this is DB2 syntax on an
> >iSeries). I didn't find the LABEL ON command in
> the
> >Derby Reference manual so I was wondering if there
> was
> >another way to do this in Derby. Does that make
> >sense?
> >
> >Thanks for the reply,
> >Jason
> >
> >--- Rajesh Kartha <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >>Hi,
> >>
> >>Is 'Select <col> as from <table>' , what you are
> >>looking for.
> >>
> >>The schema:
> >>--------------
> >>ij> select * from atab;
> >>ID |COL1|COL2
> >>---------------------
> >>1 |CA |MI
> >>
> >>1 row selected
> >>
> >>Using the 'select as'
> >>------------------------
> >>
> >>ij> select id as IDENT_NUM from atab;
> >>IDENT_NUM
> >>-----------
> >>1
> >>
> >>1 row selected
> >>
> >>
> >>-Rajesh
> >>
> >>
> >>Jason Palmatier wrote:
> >>
> >>
> >>
> >>>Does Derby support anything like LABEL ON which
> >>>
> >>>
> >>allows
> >>
> >>
> >>>you to set the label (i.e. a displayable name)
> for
> >>>
> >>>
> >>a
> >>
> >>
> >>>column after a table is created? I checked the
> >>>reference manual and it doesn't seem to but I
> >>>
> >>>
> >>wanted
> >>
> >>
> >>>to ask here to be sure.
> >>>
> >>>Thanks,
> >>>Jason
> >>>
>
>>>__________________________________________________
> >>>Do You Yahoo!?
> >>>Tired of spam? Yahoo! Mail has the best spam
> >>>
> >>>
> >>protection around
> >>
> >>
> >>>http://mail.yahoo.com
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
> >
> >
> >__________________________________
> >Do you Yahoo!?
> >Yahoo! Mail - 250MB free storage. Do more. Manage
> less.
=== message truncated ===
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo