-
how can i get the column names in a table (6 messages)
- Posted by: zhebin cong
- Posted on: November 19 2003 23:26 EST
hello
in my projects,i need to get the column names of a unknown table,i have tried the ResultSetMetaData and DatabaseMetaData objects,it seems that both of them don't work,who can give me a code snippet?
such as retrieve the column names of the emp table(the oracle sample database---scott/tiger).
thank you very much!Threaded Messages (6)
- how can i get the column names in a table by zhebin cong on November 20 2003 00:17 EST
- how can i get the column names in a table by David Rabinowitz on November 20 2003 03:01 EST
- how can i get the column names in a table by Paul Strack on November 20 2003 07:49 EST
- To get the column names........ its really working by Ranjani Bala on April 11 2004 06:37 EDT
- how can i get the column names in a table by Aashish Kaushik on November 21 2003 05:39 EST
- This could help you out by Noe Samuhel on June 17 2011 06:46 EDT
-
how can i get the column names in a table[ Go to top ]
- Posted by: zhebin cong
- Posted on: November 20 2003 00:17 EST
- in response to zhebin cong
sorry,i know that i can get it by the ResultSetMetaData.getColumnCount(int col) method,but i must execute a query first,because i know nothing about the table,the only choice is "select * from myTable",then navigate the resultset.but maybe this table have thousands of records,i only want to get the COLUMN NAME,not the record,so this method is not effective,who can give me a more effective code snippet?such as retrieve the column names of the emp table(in oracle sample database-----scott/tiger).
thank you! -
how can i get the column names in a table[ Go to top ]
- Posted by: David Rabinowitz
- Posted on: November 20 2003 03:01 EST
- in response to zhebin cong
Have you tried using DatabaseMetaData.getColumns(...) ?
David -
how can i get the column names in a table[ Go to top ]
- Posted by: Paul Strack
- Posted on: November 20 2003 07:49 EST
- in response to zhebin cong
Use a dummy query to pull results out of your table:
select * from myTable where 1=2
Since 1=2 is always false, this query will return no records, but the JDBC driver will then be able to retrieve metadata about your table. -
To get the column names........ its really working[ Go to top ]
- Posted by: Ranjani Bala
- Posted on: April 11 2004 06:37 EDT
- in response to Paul Strack
The following query really works to get the column names of a table.i think u may use this for dynamic tables it seems. use this query:
select column_name from user_tab_columns where table_name='enter the table name in caps';
example: select column_name from user_tab_columns where table_name='EMP';
Try this one and send the reply about the result.i think u can get what u need by this query. -
how can i get the column names in a table[ Go to top ]
- Posted by: Aashish Kaushik
- Posted on: November 21 2003 05:39 EST
- in response to zhebin cong
Hi ,
I have gone through some of the responses posted and found some of them to be Dumbest ever.
First you must get your Basics right.
<1>Though ResultSetMetaData does provide a method by the name of getColumnNames() but you cannot guarrante that the names of the column returned are the exact replica of the Table column name
(Consider a case where queries have Alias names defined for Column names,In that case this method will return the name of thos aliases defined)
I hope this helps.
Cheers !!!
Aashish Kaushik -
This could help you out[ Go to top ]
- Posted by: Noe Samuhel
- Posted on: June 17 2011 06:46 EDT
- in response to zhebin cong
You could try this: SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE '%watcher%'
[AND table_schema = 'database'], I believe it could help you find a specific column in an unknown table in a database. Also, try using the J1939 protocol stack, because it might be useful in your work.