hello in one of my project,i want to get the column names of a unknown table,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!
Hi Zhebin, Have you seen the answers that I (and Elango) have provided to this very same question that you posted at the Oracle (OTN) forums? Good Luck, Avi.
Joined: Jan 14, 2002
to Calvin: i don't want to execute such operation: rs = st.executeQuery("select * from [Sheet1$]"); because i only want to get the column name,not any record in the table,such a operation maybe more resource-consuming,there may be millions of record in the table.
to Avi: could you give me the CONCRETE link to the post,the link you have provided is pointed to the main page of the otn forum.
One possible way to "cheat"--and I've tested this against several different databases--is to force the query to return no rows, something like: rs = st.executeQuery("select * from [Sheet1$] where 1 = 2"); I've tested this against tables with over one million records and it returned almost immediately. But I still got the ResultSetMetaData and was able to determine the column names and types.