• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Database Tables

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 42164
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic