• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Tables

 
Bob Woodr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,
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.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic