* FILE NAME:  Long2Html.java     TITLE: export to HTML 
* AUTHOR:  Ken North, Ken North Computing, LLC
*      This is an retrieving a LONG column and exporting it to an HTML file
*      Uses the Oracle thin JDBC driver. 
*      From XML, Java, and Database Magic (Prentice-Hall, 1999)
* Copyright (c) Kendall E. North II, 1999. All rights reserved. Reproduction
* or translation of this work beyond that permitted in Section 117 of the
* United States Copyright Act without express written permission of the
* copyright owner is unlawful.
* The purchaser may make backup copies for his/her own use only and not for
* distribution or resale. The Author and Publisher assume no responsibility
* errors, omissions or damages caused by the use of these programs or from
* use of the information contained herein.

import java.sql.*;
import java.io.*;

class Long2Html
  public static void main (String args [])
       throws SQLException, ClassNotFoundException, IOException

                              // load the Oracle driver
    Class.forName ("oracle.jdbc.driver.OracleDriver");
                              // specify the connection URL
    String url = "jdbc:oracle:thin:@burns:1521:magic";

                             //   connect to data source
    Connection conn = DriverManager.getConnection(url,"north","north2");

                            // create JDBC Statement for SQL statement
    Statement stmt = conn.createStatement ();

                         // query to get the row with name 'PrimeFacilities'
    ResultSet rs = 
      stmt.executeQuery ("SELECT bp_data FROM boilerplate WHERE bp_ident='PrimeFacilities'");
                        // process ResultSet data
    if (rs.next ())
                        // get the HTML text using a result set input stream to
                        // retrieve data from a LONG column
      InputStream web_text = rs.getAsciiStream (1);

                        // open the export (HTML) file
      FileOutputStream ostr = new FileOutputStream ("Events.htm");
                        // fetch-write loop: fetch HTML column data, write to file 
      int i;
      while ((i = web_text.read ()) != -1)
        ostr.write (i);

                        // close the file
      ostr.close ();
                        // close result set, connection, statement
    if (rs != null)
    if (stmt != null)
    if (conn != null)