FileDocCategorySizeDatePackage
TestLongGetCharacterStream.javaAPI DocExample2232Mon Dec 11 13:29:46 GMT 2000None

TestLongGetCharacterStream

public class TestLongGetCharacterStream extends Object

Fields Summary
Connection
conn
Constructors Summary
TestLongGetCharacterStream()

  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@devdb02:1521:ohsdb", "oehr", "rheo" );
  }
  catch (ClassNotFoundException e) {
   System.err.println("Class Not Found Error: " + e.getMessage());
   System.exit(1);
  }
  catch (SQLException e) {
   System.err.println("SQL Error: " + e.getMessage());
   System.exit(1);
  }
 
Methods Summary
protected voidfinalize()

  if (conn != null) try { conn.close(); } catch (SQLException ignore) { }
  super.finalize();
 
public static voidmain(java.lang.String[] args)

  new TestLongGetCharacterStream().process(); 
 
private voidprocess()

  FileWriter fout      = null;
  int        rows      = 0;
  long       person_id = 7;
  Statement  stmt      = null;
  Reader     in        = null;
  ResultSet  rslt      = null;
  try {
   conn.setAutoCommit(false);

   stmt = conn.createStatement();
   rslt = stmt.executeQuery(
    "select biography " + 
    "from   person_biography " + 
    "where  person_id = " + Long.toString(person_id));
   rslt.next();
 
   File fileName = new File("tim.uni");
   fout = new FileWriter(fileName);
   in = rslt.getCharacterStream(1);
   char[] buffer = new char[32];
   int length  = 0;
   while ((length = in.read(buffer)) != -1) {
    fout.write(buffer, 0, length);
   }

   fout.close();
   fout = null;

   in.close();
   in = null;

   rslt.close();
   rslt = null;

   stmt.close();
   stmt = null;
 
   conn.commit();
  }
  catch (IOException e) {
   System.out.println("IO Error: " + e.getMessage());
   System.exit(1);
  }
  catch (SQLException e) {
   System.out.println("SQL Error: " + e.getMessage());
   System.exit(1);
  }
  finally {
   if (rslt != null) try { rslt.close(); } catch (SQLException ignore) { }
   if (stmt != null) try { stmt.close(); } catch (SQLException ignore) { }
   if (fout != null) try { fout.close(); } catch (IOException ignore) { }
   if (in   != null) try { in.close();   } catch (IOException ignore) { }
  }