Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Retrive the CLOB value from Oracle using java

Tags:

java

SELECT DESCRIPTION,DETAILED_DESCRIPTION,PRIORITY,RISK_LEVE FROM Table_Name

The DETAILED_DESCRIPTION column is having value in CLOB

Below is the code is used to fetch the data: But i am getting the error "Error: Read error" while reading the field "DETAILED_DESCRIPTION"

Statement statement;

ResultSet resultSet;

oracleCon.setAutoCommit(false);

statement = oracleCon.createStatement();

String chdet[] = new String[8];
String query="SELECT DESCRIPTION,DETAILED_DESCRIPTION,PRIORITY,RISK_LEVEL FROM Table_Name"; 

                    resultSet = statement.executeQuery(query);
                    ArrayList<String> record=new ArrayList<String>();               

                    while (resultSet.next())
                    {
                    record.add(resultSet.getString("DESCRIPTION"));                 
                    record.add(resultSet.getString("DETAILED_DESCRIPTION"));
                    record.add(resultSet.getString("PRIORITY"));
                    record.add(resultSet.getString("RISK_LEVEL"));              
                    }                   
                    if(record.size()>0)             
                    {
                        chdet[0] = record.get(0);
                        chdet[1] = record.get(1);
                        chdet[2] = record.get(2);
                        chdet[3] = record.get(3);
                        break;                          
                    }                               
                }
            return chdet;   
like image 453
user1882624 Avatar asked Oct 21 '13 05:10

user1882624


People also ask

How do I search CLOB data?

CLOBs require that you use the DBMS_LOB package to perform substr/instr type searches. In order to use do any kind of searching within the column, you must first get the locator for the CLOB column, the use the DBMS_LOB. SUBSTR or DBMS_LOB. INSTR function to search and/or pull part of the text from the string.

What is Java SQL CLOB?

An SQL CLOB is a built-in type that stores a Character Large Object as a column value in a row of a database table. By default drivers implement a Clob object using an SQL locator(CLOB) , which means that a Clob object contains a logical pointer to the SQL CLOB data rather than the data itself.


1 Answers

After retrieving your data, you can use the getClob () method to return your Clob. Then you needs to open the Clob's stream to read the data (Mayb be char or binary data).

If the clob is known to be a plain string, you maybe also wish to use

clob.getSubString(1, (int) clob.length());

So try this

Clob clob = resultSet.getClob("DETAILED_DESCRIPTION")
record.add(clob.getSubString(1, (int) clob.length());

see http://www.java2s.com/Code/JavaAPI/java.sql/ResultSetgetClobintcolumnIndex.htm

like image 147
Scary Wombat Avatar answered Oct 05 '22 22:10

Scary Wombat