> -----Message d'origine-----
> De : Erwan TROEL
> Envoy� : mercredi 23 ao�t 2000 14:08
> � : '[EMAIL PROTECTED]'
> Objet : re: out.println
>
> Quand j'utilise out.println dans:
>
>
>
>
>
> <%@ page language="java" import="java.sql.*" %>
> <%!
>
> // presentation
> final String styleTableBeg = "<TABLE>";
> final String styleTableEnd = "</TABLE>";
> final String styleDataRowBeg = "<TR>";
> final String styleDataRowEnd = "</TR>";
> final String styleHeaderCellBeg = "<TH>";
> final String styleHeaderCellEnd = "</TH>";
> final String styleStringCellBeg = "<TD>";
> final String styleStringCellEnd = "</TD>";
>
> // database connection
> final String drv = "sun.jdbc.odbc.JdbcOdbcDriver";
> final String url = "jdbc:odbc:mabase";
> final String login = "";
> final String psw = "";
>
> // Encodage HTML
> String HTMLEncode( String str ) {
> String res = "";
>
> if( str == null ) return res;
>
> for( int i = 0; i < str.length(); i++ ) {
> char c = str.charAt( i );
> switch( c ) {
> case '<' : res += "<"; break;
> case '>' : res += ">"; break;
> case '&' : res += "&"; break;
> default : res += c;
> }
> }
>
> return res;
> }
>
> // Fabrique un �tat sur une table quelconque
> void doReport( String query, JspWriter out) {
> Connection con;
> Statement stmt;
> ResultSet rs;
> ResultSetMetaData md;
> int numCols;
>
> // open driver
> try {
> Class.forName( drv );
> } catch( Exception ex ) {
> out.println( "<P>erreur : driver " + drv + " : " + ex );
> return;
> }
>
> try {
> con = DriverManager.getConnection( url, login, psw );
> stmt = con.createStatement();
> rs = stmt.executeQuery(query);
> md = rs.getMetaData();
> numCols = md.getColumnCount();
>
> // print headers
> out.println( "styleTableBeg" );
> out.println( styleDataRowBeg );
> for( int i = 1; i <= numCols; i++ ) {
> out.println( styleStringCellBeg );
> out.println( HTMLEncode( md.getColumnName( i ) ) );
> out.println( styleStringCellEnd );
> }
> out.println( styleDataRowEnd );
>
> // report loop
> while( rs.next() ) {
> out.println( styleDataRowBeg );
> for( int i = 1; i <= numCols; i++ ) {
> out.println( styleStringCellBeg );
> out.println( HTMLEncode( rs.getString( i
> )));
> out.println( styleStringCellEnd );
> }
> out.println( styleDataRowEnd );
> }
>
> out.println( styleTableEnd );
>
> stmt.close();
> con.close();
> }
> catch( SQLException ex ) {
> out.println( "</table><P>SQLException: " + ex + "</P>" );
> }
>
> }
>
> %>
> <html>
> <head>
> <title>Mon Premier Etat avec JSP et JDBC</title>
> <link rel="stylesheet" type="text/css" href="style.css">
> </head>
> <body>
> <%
> String strTableName = request.getParameter("TableName");
> if( strTableName != null ) {
> %>
> <H1>Liste des enregistrements de <%=HTMLEncode( strTableName
> )%></h1>
> <p>
> <%
> doReport( "select * from " + strTableName, out );
>
> %>
> </p>
> <%
> }
> else {
> %>
> <h1>Etat d'une Table</h1>
> <form action="myfirst.jsp" method="post">
> <p>Nom de la table: <input type="text" name="TableName"></p>
> <p><input type="submit"></p>
> </form>
> <%
> }
> %>
> <hr>
> </body>
> </html>
> J' ai le message d'erreur:
> org.apache.jasper.JasperException: Unable to compile class for
> JSPC:\jakarta-tomcat\work\localhost_8080\_0002fmyfirst_0002ejspmyfirst_jsp
> _20.java:80: Exception java.io.IOException must be caught, or it must be
> declared in the throws clause of this method. out.println( "styleTableBeg"
> );
> Peux tu m'aider merci
>
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets