File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to get table names ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to get table names ?" Watch "How to get table names ?" New topic
Author

How to get table names ?

Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Hi all,

I am using oracle 9i, how can i get the list of table in a particular database. i have seen few posts in the forum and tried according to that, but no luck still.

My database configuration is,

sid = web
username = scot
password = tiger
database name = test

I am trying to use DatabaseMetaData.getTables(String,String,String,String)

what is catalog in my context
what is schemaPattern in my context
what is tableNamePattern in my context
what is columnNamePattern in my context

I understand from the previous posts that, the ResultSetMetaData.tableName(int) is not working with Oracle.

I hope you guys understand my problem, I am very new in DBMS.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

sanju,

do you want know table names in java or on sql plus
if sql plus then this query will do the job




shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
I wanted to know in java, using JDBC.
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 375
ResultSet rset;

.....

rset.getMetaData() has a bunch of access functions
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
I tried using ResultSetMetaData, ResultSetMetaData.getTableName(int) is not working with oracle ojdbc14 drivers. and tried using DatabaseMetaData.

The code is,



I want to know, what I should use instead of xxxx in the method params. please see my database infos in the first post.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

[This was typed and posted before Sanjus's above Post]


Originally posted by -Sanju Thomas-:
I wanted to know in java, using JDBC.


1) Create the Connection to Database
2) Invoke the method getMetaData()

DatabaseMetaData dm = conection.getMetaData()

3) Now you have DatabaseMetaData (dm)invoke the dm.getTables()

catalog -- pass this as connection.getCatalog()
SchemaPattern -- your schmea patters
tableNamePattern -- pattern name for lable for example you need table starting with 'S' so pass it as 'S%'
types -- list of table types to include

you will get a resultset of tables and you can get table names as rs.getString("TABLE_NAME")


for more detail refer javadoc.


hope this helps

Shailesh
[ April 15, 2005: Message edited by: Shailesh Chandra ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

Originally posted by -Sanju Thomas-:

I want to know, what I should use instead of xxxx in the method params. please see my database infos in the first post.


Sanju,

As I mentioned in my last post these are the parameter to narrow the search
for catalog,schemaPattern and types you can pass null they would not be consider to narrow your search

and for table name pattern I am not sure but you pass it as "%" this should retrun all table.

Shailesh
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Thank you, Thank you very much Shailesh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get table names ?
 
Similar Threads
JDBC newbie
Converting String to Date???
No. of rows in a table
Determine String encoding
How to retrieve an imagefrom frontend?