Note this isn't a JSP question -- this is a rather fundamental question
about JDBC. Please consult one of the books about JDBC, such as "JDBC
Database Access with Java" by Hamilton et. al.
Well, first you need to get the ResultSet object from the query. If you
know the columns that will be returned, you could hard-code them.
Otherwise, you will need to get the ResultSetMetaData object from the
ResultSet and read the column names & data types.
Note that this code really belongs in a Bean or Servlet, not directly in
a .jsp page -- JSP pages should be mostly HTML content.
int row = 0;
int col = 0;
ResultSet rs = stmt.executeQuery(.....);
ResultSetMetaData md = rs.getMetaData();
out.println("<TABLE>");
while( rs.next() ) {
// If this is the first row, use the metadata to print col headings
if( row == 0 ) {
out.print("<TR>");
for( col=1; col <= md.getColumnCount(); ++col ) {
out.print("<TH>"+md.getColumnLabel(col)+"</TH>");
}
out.println("</TR>");
}
++row;
// For each subsequent row, make the assumption that everything can
// be retrieved as a String.
out.print("<TR>");
for( col=1; col <= md.getColumnCount(); ++col ) {
out.print("<TD>"+rs.getString(col)+"</TD>");
}
out.println("</TR>");
}
out.println("</TABLE>");
// Make sure the JDBC objects can be reclaimed by the garbage collector.
md = null;
rs.close();
rs = null;
stmt.close();
stmt = null;
Guilherme - PerConsult wrote:
> <%
> String pesquisa = "select * from pessoa where nome = 'gui2'";
> stmt.executeQuery(pesquisa);
> %>
>
> <p>fim</p>
>
> </body>
> </html>
>
> On Control Panel I set my database as "teste" (the bridge). I have some
> data on the table "pessoa" to make the query also..
>
> Well.... the code is okay. But I don`t know how to print the result of
> this query on the screen.... in the JSP file...
>
> Can anybody help me???
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html