7
SELECT DESCRIPTION,DETAILED_DESCRIPTION,PRIORITY,RISK_LEVE FROM Table_Name

DETAILED_DESCRIPTION列在CLOB

下面是用于获取数据的代码:但我在读取字段“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;   
4

2 回答 2

22

检索数据后,您可以使用 getClob() 方法返回您的 Clob。然后你需要打开 Clob 的流来读取数据(可能是 char 或二进制数据)。

如果已知 clob 是纯字符串,您可能还希望使用

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

所以试试这个

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

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

于 2013-10-21T05:18:46.947 回答
0

这可能对你有帮助,

    // Select LOB locator into standard result set.
ResultSet rs =
   stmt.executeQuery ("SELECT blob_col, clob_col FROM lob_table");
while (rs.next())
{
   // Get LOB locators into Java wrapper classes.
   java.sql.Blob blob = rs.getBlob(1);
   java.sql.Clob clob = rs.getClob(2);

}

有关详细信息,请参阅以下链接, http://docs.oracle.com/cd/A84870_01/doc/java.816/a81354/oralob2.htm

于 2013-10-21T05:16:38.787 回答