As well known I can retrieve the column names by a java code similar to the one below.
But how do I put the column names into the database which I retrieve later?
There is no function like putColumnName()
ResultSetMetaData rsmd = rs.getMetaData();
int maxcol = rsmd.getColumnCount();
for(int col=1; col<=maxcol; col++)
System.out.println(rsmd.getColumnName(col));
Arni
Joe Weinstein - 16 Oct 2004 18:32 GMT
> As well known I can retrieve the column names by a java code similar to the one below.
> But how do I put the column names into the database which I retrieve later?
[quoted text clipped - 4 lines]
> for(int col=1; col<=maxcol; col++)
> System.out.println(rsmd.getColumnName(col));
DatabaseMetaData.getColumns().
Joe Weinstein at BEA
> Arni
Woebegone - 16 Oct 2004 20:15 GMT
> As well known I can retrieve the column names by a java code similar to
> the one below.
[quoted text clipped - 8 lines]
>
> Arni
Are you talking about creating tables/columns in the database? This requires
that you execute an update query consisting of a CREATE or ALTER TABLE
statement with your DDL (and depends on what your DB allows). On the other
hand, if you're just trying to store the names you've gotten for later use,
you could use "String[] columnNames = new String[maxcol];" and inside your
loop "columnNames[i - 1] = rsmd.getColumnName(col);"
HTH,
Sean.
Ann - 17 Oct 2004 03:00 GMT
> As well known I can retrieve the column names by a java code similar to the one below.
> But how do I put the column names into the database which I retrieve later?
[quoted text clipped - 6 lines]
>
> Arni
ALTER TABLE <name> CHANGE COLUMN <oldname> <newname>
or similar
Paul Lutus - 17 Oct 2004 06:34 GMT
> As well known I can retrieve the column names by a java code similar to
> the one below. But how do I put the column names into the database which I
> retrieve later? There is no function like putColumnName()
Tell us what problem you are trying to solve. The database already has field
names. Do you want to change the field names for the database records? To
do this, you normally create an entirely new table.

Signature
Paul Lutus
http://www.arachnoid.com
Oscar kind - 17 Oct 2004 14:20 GMT
In comp.lang.java.help Arnold Peters <apet10@hotmail.com> wrote:
> As well known I can retrieve the column names by a java code similar to the one below.
> But how do I put the column names into the database which I retrieve later?
> There is no function like putColumnName()
No; the meta data classes provide information about the database that is
not always available in a uniform manner using SQL. They are purely for
information only.
To change/add/remove a column in a database, use SQL queries like "alter
table ...".

Signature
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2