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
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);
-
1