File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Database Tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Database Tables" Watch "Database Tables" New topic

Database Tables

Bob Woodr

Joined: Feb 09, 2006
Posts: 3
How can I find out all the tables currently defined in an oracle database? How can I do this with JSP? I just want to have a JSP page that prints out all the tables names. Also how can I print out all the attributes of a specific table? also in JSP? thanks
Sunil Dumpala

Joined: Jul 28, 2005
Posts: 29
The following query returns the names of all the tables in Oracle Database.

select table_name from user_tables;

JDBC can be used to run the query, retrieve the resultset, parse it and display the Table Names in JSP.
Bob Woodr

Joined: Feb 09, 2006
Posts: 3
once I know the name of the tables, how can I find out the attributes and their datatypes?

For example if I have table A which has (col1 VARCHAR(10), col2 INT)

but I only know that there is a table A, how can I find out the other info? thanks
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32811

Kyle Brown (who incidentally is a bartender here) wrote a good article that walks you through using metadata. He shows how to get a list of tables (which you now know) and how to get column info from those tables..

Also, note that it is good practice to do JDBC outside the JSP. You can put it in a Java class. Then call that class from a servlet and forward to a JSP. This creates a cleaner, more maintainable JSP.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Using DatabaseMetaData is the standard JDBC, databse-independent way of doing it.

In Oracle, there are a large number of "data dictionary" views potentially available to you (although access to them and the results they return to you will vary depending on database version and your user privileges and the security setup in your database).

You can see what's potentially available with:

Personally, I find USER_OBJECTS, USER_TABLES, USER_TAB_COLUMNS, and USER_VIEWS to be the most useful (or the ALL version), day-to-day.
I agree. Here's the link:
subject: Database Tables
It's not a secret anymore!