<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<HTML>
<HEAD>
<TITLE>Using Table Metadata</TITLE>
</HEAD>
<BODY>
<H1>Using Table Metadata</H1>
<%
Connection connection = DriverManager.getConnection(
"jdbc:odbc:data", "YourName", "password");
Statement statement = connection.createStatement() ;
ResultSet resultset = statement.executeQuery("select * from Publishers") ;
%>
<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>
|