A relational table has a finite set of columns (column names must be unique and each might have a different data type). In GUI database applications, in order to manipulate a relational table, you need to understand column names and types. Also, for a web-based application, you need to know the primary key (PK) columns before inserting new records (to make sure that the PK columns cannot be NULL).
The DatabaseMetaData.getColumns() method retrieves a description of table columns available in the specified catalog. The method’s signature is
Only column descriptions matching the catalog, schema, table, and column name criteria are returned. They are ordered by TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION. Each column description has the columns shown in Table.
Table : Column Descriptions
The parameters are
As you can see, this method returns its result as a ResultSet object (each row is a detailed column description), which is not very useful for web-based applications. Next I present a Java servlet (GetColumns), which will be able to get a table’s columns (as well as other related metadata information) as HTML or XML. Here is the signature of the servlet:
GetColumns?vendor=<vendor-name>&table=<table-name>&format=<HTML-or-XML>You may add other parameters to suit your database application. Here, I use vendor to act as a database selector. So, to get the employee table’s columns information as XML for a MySQL database, you may invoke it as
GetColumns?vendor=mysql&table=employees&format=xmlThe other possibilities are
MySQL Database Setup
Oracle Database Setup
The Solution
Invoking GetColumns for MySQL
Figure :shows how to run the solution for the MySQL database.
Invoking GetColumns for Oracle
Figure :shows how to run the solution for the Oracle database.
JDBC Related Interview Questions |
|
---|---|
Core Java Interview Questions | JSP Interview Questions |
Java Servlets Interview Questions | EJB(Enterprise JavaBeans) Interview Questions |
JSTL(JSP Standard Tag Library) Interview Questions | JNDI (Java Naming and Directory Interface) Interview Questions |
Java Bean Utils Interview Questions | AWT (Abstract Window Toolkit) Interview Questions |
Jdbc Tutorial
What Is Jdbc Programming?
Database Metadata, Part 1
Database Metadata, Part 2
Resultset Metadata
Parameter Metadata
Exploring Driver Property Information
Rowset Metadata A
Web Access To Metadata,part 1
Web Access To Metadata, Part 2
Rdf And Jdbc Metadata
Text Resumes
Visual Resumes
Social Resumes
Resume Quality
IT Resume Samples
MARKETING Resume Samples
HR Resume Samples
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.