How to Read CLOBs in Java

The Java programming language can interface with SQL databases. One way Java accomplishes this is by reading SQL CLOB data. CLOB stands for Character Large Object and is a means of storing information. CLOBs are usually used for storing data outside of a database. The database merely refers to the location of the CLOB data. If you have a SQL server with CLOB data, you can access it using Java. The Java CLOB class provides a means for converting CLOB data into streams of characters, which can be read using a BufferedReader.

Things You'll Need

  • Java Software Development Kit with NetBeans Integrated Development Environment (IDE) Bundle
Show More

Instructions

    • 1

      Load the NetBeans IDE by clicking on its program icon. When the program loads, navigate to "New/New Project" and select "Java Application" from the list on the right-hand side of the screen. A new source code file appears in the NetBeans text editor. The source code file contains an empty main function.

    • 2

      Create a new BufferedReader object and set its value to a CLOB ASCII stream. For example, if your CLOB object was named "myCLOB," you could create a BufferedReader like this:

      BufferedReader reader = new BufferedReader(new

      InputStreamReader(myCLOB.getAsciiStream()));

    • 3

      Create a new string named n like this:

      String s = null;

    • 4

      Iterate through the BufferedReader to view the data held by the CLOB. You can do this with a while loop that looks like this:

      while((s = reader.readLine()) != null )

      {

      }

    • 5

      Print out the data held by the BufferedReader by sending it to the println function. You can do this by placing this statement within the curly brackets of the while loop:

      System.out.println(s);

Related Searches:

References

Resources

Comments

You May Also Like

  • How to Read XLS Files in Java

    The Excel application is a Microsoft product installed on Windows machines. The Java language is used to create web applications that run...

  • How to Update a CLOB Field

    CLOB, or Character Large OBject, is a data type that stores a large amount of text data in Oracle databases. External CLOB...

  • How to Make Infinite Coins in Club Penguin

    Released in 2005 by Club Penguin Entertainment and Disney, Club Penguin is an online role-playing game that drops you into the shoes...

  • How to Use BufferedInputStream in Java

    The BufferedInputStream is a class in the Java Input/Output (IO) library designed to allow a programmer to read data from an InputStream,...

Related Ads

Featured