Forums Register Login

Database Tables

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1023 times.
Similar Threads
Listing tables in mySQL
List all the tables using hibernate
names and properties of tables in database using jdbc
How to detect the database is NULL or not
Transfer data from Access DB to Oracle DB and Vice Versa in a java program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:20:07.