title: Error while retieving CLOB from Oracle 10g
body: <p>The Following code attempts to retrieve a CLOB file from oracle database in JDBC.</p>
  
  <p>Code:-</p>
  
  <pre><code>import java.io.FileWriter;
  import java.io.Reader;
  import java.sql.Clob;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.util.Properties;
  
  public class Retrieving_Clob {
  
  public static void main(String[] args) throws Exception{
  
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  
      Properties p = new Properties();
      p.put("user", "system");
      p.put("password", "password");
  
      Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",p);
  
      PreparedStatement pstmt = con.prepareStatement("select * from  myclob");
  
      ResultSet rs = pstmt.executeQuery();
  
      rs.next();
  
       Reader r = rs.getCharacterStream(1);
  
      int ch;
  
      File file = new File("H:/newFile.txt");
  
      FileWriter fw = new FileWriter(file,true);
  
      while((ch= r.read())!= -1)
          fw.write((char)ch);
  
      fw.close();
      con.close();
  }
  }
  </code></pre>
  
  <p>I am trying to retrieve the CLOB file from the resultset index=1.The code is giving me the following error:-</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at jdbc.Retrieving_Clob.main(Retrieving_Clob.java:41)
  </code></pre>
  
  <p>The erroneous line being:-</p>
  
  <pre><code>        while((ch= r.read())!= -1)
  </code></pre>
  
  <p>What is the reason for the error and how to solve the problem?</p>
  
  <p><strong>Note :-</strong> A blank file by the provided name is getting created at the given location.</p>