How to Work With Metadata in JSP


This is the next article in the series of database applications in JSP. In this article, I am going to describe the metadata in JSP. First we construct a database and then make the DSN generate a JSP application that uses the metadata concept. To construct a database and DSN you may follow the first application of database ( working with database application in JSP).

For this application you may follow the following steps.

Step 1 :
Create a New Project

In this step we select New Project option from file menu.

create new project.jpg

Step 2 : Choose Project

In this step we select web application from Java web option and then click on the next button.

select new web application.jpg

Step 3 : Name and Location

In this step we give it a specific name and set a specific location and click on the next button.

name and location.jpg
 

Step 4 : Server and Setting

We select a specific server for this application and click on the next button.

server and setting.jpg

Step 5 : Select Framework

There is no need to select any framework for this application, so just click on the finish button.

selectframework.jpg

Step 6 : Create jsp file

We create one jsp file for this application.

create new jsp file.jpg

metadata.jsp

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<HTML>
         <HEAD>
         <TITLE>
Using Metadata In Table</TITLE>
         </HEAD>
         <BODY BGCOLOR="green">
             <H1>Using Metadata In Table</H1>
             <%
                 Connection connection = DriverManager.getConnection(
                  "jdbc:odbc:data2");
                 Statement statement = connection.createStatement() ;
                 ResultSet resultset =
                 statement.executeQuery("select * from table1") ;
             %>
                 <TABLE BORDER="1">
                 <TR>
                      <TH><%= resultset.getMetaData().getColumnName(1)%></TH>
                      <TH><%= resultset.getMetaData().getColumnName(2)%></TH>
                      <TH><%= resultset.getMetaData().getColumnName(3)%></TH>
                      <TH><%= resultset.getMetaData().getColumnName(4)%></TH>
                      <TH><%= resultset.getMetaData().getColumnName(5)%></TH>
                   </TR>
            <% while(resultset.next()){ %>
                 <TR>
                      <TD> <%= resultset.getString(1) %></td>
                     <TD> <%= resultset.getString(2) %></TD>
                     <TD> <%= resultset.getString(3) %></TD>
                     <TD> <%= resultset.getString(4) %></TD>
                     <TD> <%= resultset.getString(5) %></TD>
                 </TR>
           <% } %>
                 </TABLE>
        </BODY>
</HTML>


Step 7 :
Compile and Run the application

Now we compile the application and then run it on the server and find the following output.

Output

metadata.jsp

index.jsp.jpg

Resources related to this article

Up Next
    Ebook Download
    View all
    Learn
    View all