/**************************************************************************** * FILE NAME: Html2Long.java TITLE: Import HTML into a LONG * * AUTHOR: Ken North, Ken North Computing, LLC * * This is an example of reading a text file (HTML) and storing it in * a LONG using 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 Html2Long { 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 (); // DROP the existing boilerplate table try { stmt.execute ("DROP TABLE boilerplate"); } catch (SQLException e) { // catch and ignore table not found exception } // CREATE the biolerplate table to store HTML boilerplate stmt.execute ("CREATE TABLE boilerplate (bp_ident VARCHAR2 (128), bp_data LONG)"); // read from HTML file using input stream File file = new File ("moreinfo.htm"); InputStream istr = new FileInputStream ("moreinfo.htm"); // Do a prepared INSERT into the bp_data column PreparedStatement pstmt = conn.prepareStatement ("INSERT INTO boilerplate (bp_data, bp_ident) VALUES (?, ?)"); pstmt.setAsciiStream (1, istr, (int)file.length ()); pstmt.setString (2, "PrimeFacilities"); pstmt.execute (); // close connection, statement if (pstmt != null) pstmt.close(); if (conn != null) conn.close(); } }