JavaTM 2 Platform
Standard Ed. 5.0

java.sql
接口 Clob

所有已知实现类:
SerialClob

public interface Clob

SQL 类型 CLOB 在 JavaTM 编程语言中的映射关系。SQL CLOB 是内置类型,它将 Character Large Object 存储为数据库表的某一行中的一个列值。默认情况下,驱动程序使用 SQL locator(CLOB) 实现 Clob 对象,这意味着 CLOB 对象包含一个指向 SQL CLOB 数据而不是数据本身的逻辑指针。Clob 对象在它被创建的事务处理期间有效。

CLOB 接口提供某些方法来获得 SQL CLOB (Character Large Object) 值长度、在客户端实现 CLOB 值以及搜索子字符串或 CLOB 值中的 CLOB 对象。接口 ResultSetCallableStatementPreparedStatement 中的方法(如 getClobsetClob)允许编程人员访问 SQL CLOB 值。此外,此接口还拥有更新 CLOB 值的方法。

从以下版本开始:
1.2

方法摘要
 InputStream getAsciiStream()
          以 ascii 流形式检索由此 Clob 对象指定的 CLOB 值。
 Reader getCharacterStream()
          以 java.io.Reader 对象形式(或字符流形式)检索此 Clob 对象指定的 CLOB 值。
 String getSubString(long pos, int length)
          检索此 Clob 对象指定的 CLOB 值中指定子字符串的副本。
 long length()
          检索此 Clob 对象指定的 CLOB 值中的字符数。
 long position(Clob searchstr, long start)
          检索此 Clob 对象中指定的 Clob 对象 searchstr 出现的字符位置。
 long position(String searchstr, long start)
          检索由此 Clob 对象表示的 SQL CLOB 值中指定子字符串 searchstr 出现的字符位置。
 OutputStream setAsciiStream(long pos)
          检索用于将 Ascii 字符写入此 Clob 对象表示的 Clob 值中的流,从位置 pos 处开始。
 Writer setCharacterStream(long pos)
          检索用于将 Unicode 字符流写入此 Clob 对象表示的 CLOB 值中(位置 pos 处)的流。
 int setString(long pos, String str)
          在位置 pos 处将给定 Java String 写入此 Clob 对象指定的 CLOB 值中。
 int setString(long pos, String str, int offset, int len)
          将 strlen 个字符写入此 Clob 表示的 CLOB 值中,从字符 offset 开始。
 void truncate(long len)
          截取此 Clob 指定的 CLOB 值,使其长度为 len 个字符。
 

方法详细信息

length

long length()
            throws SQLException
检索此 Clob 对象指定的 CLOB 值中的字符数。

返回:
CLOB 的字符长度
抛出:
SQLException - 如果访问 CLOB 值的长度时发生错误
从以下版本开始:
1.2

getSubString

String getSubString(long pos,
                    int length)
                    throws SQLException
检索此 Clob 对象指定的 CLOB 值中指定子字符串的副本。子字符串开始于位置 pos 处,有 length 个连续字符。

参数:
pos - 要提取的子字符串的第一个字符。第一个字符位于位置 1 处。
length - 要复制的连续字符的数量
返回:
一个 String,它是由此 Clob 对象指定的 CLOB 值中的指定子字符串
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.2

getCharacterStream

Reader getCharacterStream()
                          throws SQLException
java.io.Reader 对象形式(或字符流形式)检索此 Clob 对象指定的 CLOB 值。

返回:
包含 CLOB 数据的 java.io.Reader 对象
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.2
另请参见:
setCharacterStream(long)

getAsciiStream

InputStream getAsciiStream()
                           throws SQLException
以 ascii 流形式检索由此 Clob 对象指定的 CLOB 值。

返回:
包含 CLOB 数据的 java.io.InputStream 对象
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.2
另请参见:
setAsciiStream(long)

position

long position(String searchstr,
              long start)
              throws SQLException
检索由此 Clob 对象表示的 SQL CLOB 值中指定子字符串 searchstr 出现的字符位置。从位置 start 开始搜索。

参数:
searchstr - 要搜索的子字符串
start - 开始搜索的位置;第一个位置是 1
返回:
子字符串出现的位置,如果子字符串没有出现,则返回 -1;第一个位置是 1
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.2

position

long position(Clob searchstr,
              long start)
              throws SQLException
检索此 Clob 对象中指定的 Clob 对象 searchstr 出现的字符位置。从位置 start 开始搜索。

参数:
searchstr - 要搜索的 Clob 对象
start - 开始搜索的位置;第一个位置是 1
返回:
Clob 对象出现的位置,如果子字符串没有出现,则返回 -1;第一个位置是 1
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.2

setString

int setString(long pos,
              String str)
              throws SQLException
在位置 pos 处将给定 Java String 写入此 Clob 对象指定的 CLOB 值中。

参数:
pos - 开始写入此 Clob 对象表示的 CLOB 值的位置
str - 要写入此 Clob 指定的 CLOB 值中的字符串
返回:
写入的字符数
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.4

setString

int setString(long pos,
              String str,
              int offset,
              int len)
              throws SQLException
strlen 个字符写入此 Clob 表示的 CLOB 值中,从字符 offset 开始。

参数:
pos - 开始写入此 CLOB 对象的位置
str - 要写入此 Clob 对象表示的 CLOB 值中的字符串
offset - str 中开始读取要写入字符的偏移量
len - 要写入的字符数
返回:
写入的字符数
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.4

setAsciiStream

OutputStream setAsciiStream(long pos)
                            throws SQLException
检索用于将 Ascii 字符写入此 Clob 对象表示的 Clob 值中的流,从位置 pos 处开始。

参数:
pos - 开始写入此 CLOB 对象的位置
返回:
可将 ASCII 编码字符写入其中的流
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.4
另请参见:
getAsciiStream()

setCharacterStream

Writer setCharacterStream(long pos)
                          throws SQLException
检索用于将 Unicode 字符流写入此 Clob 对象表示的 CLOB 值中(位置 pos 处)的流。

参数:
pos - 开始写入 CLOB 值中的位置
返回:
可将 Unicode 编码字符写入其中的流
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.4
另请参见:
getCharacterStream()

truncate

void truncate(long len)
              throws SQLException
截取此 Clob 指定的 CLOB 值,使其长度为 len 个字符。

参数:
len - CLOB 值应被截取的字节长度
抛出:
SQLException - 如果访问 CLOB 值时发生错误
从以下版本开始:
1.4

JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策