JDK8 API——java.sql.Array

本文介绍了Java中SQL ARRAY接口的应用及其实现类SerialArray。详细解释了如何通过Array接口获取SQL ARRAY值的内容,并提供了创建自定义映射的方法。此外还介绍了如何使用不同类型映射来获取数组或结果集。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.sql

Interface Array

实现该接口的类:SerialArray

java编程语言对于SQL类型ARRAY的映射。默认情况下,一个Array值是对一个SQL ARRAY的值持久事务引用。默认情况下,Array对象是使用SQL LOCATOR(array)内部实现的,这意味着一个Array对象包含一个逻辑指向SQL ARRAY 数组中数据的指针,而不是包含ARRAY值的数据。

Array接口提供方法把SQL ARRAY值的数据以数组或ResultSet对象的形式传到客户端。如果SQL ARRAY的元素是UDT (用户自定义类型) 的,则可以自定义映射。要创建一个自定义映射,一个程序员必须做两件事:

  • 新建一个类实现SQLData接口以使UDT可以自定义映射
  • 创建一个类型映射的条目包括:
  1. 完全有效的UDT的SQL类型名
  2. 实现了SQLData接口的类的对象
一种用于基类型的条目的类型映射提供给getArray 和 getResultSet两个方法,它包含的映射信息将用于ARRAY值的映射。如果没有提供类型映射,会使用默认的连接的类型映射。如果没给基类型提供类型映射或连接类型映射,则元素的映射依照标准类型映射。

JDBC驱动支持的数据类型必须实现Array接口的所有方法。

  • Since: 1.2
    • Method Summary

      All Methods Instance Methods Abstract Methods
      Modifier and Type Method and Description
      void free()
      This method frees the  Array object and releases the resources that it holds.
      Object getArray()
      Retrieves the contents of the SQL  ARRAY value designated by this  Array object in the form of an array in the Java programming language.
      Object getArray(long index, int count)
      Retrieves a slice of the SQL  ARRAY value designated by this  Array object, beginning with the specified  index and containing up to  count successive elements of the SQL array.
      Object getArray(long index, int count, Map<String,Class<?>> map)
      Retreives a slice of the SQL  ARRAY value designated by this  Array object, beginning with the specified index and containing up to  count successive elements of the SQL array.
      Object getArray(Map<String,Class<?>> map)
      Retrieves the contents of the SQL  ARRAY value designated by this  Array object.
      int getBaseType()
      Retrieves the JDBC type of the elements in the array designated by this  Array object.
      String getBaseTypeName()
      Retrieves the SQL type name of the elements in the array designated by this  Array object.
      ResultSet getResultSet()
      Retrieves a result set that contains the elements of the SQL  ARRAY value designated by this  Arrayobject.
      ResultSet getResultSet(long index, int count)
      Retrieves a result set holding the elements of the subarray that starts at index  index and contains up to  count successive elements.
      ResultSet getResultSet(long index, int count, Map<String,Class<?>> map)
      Retrieves a result set holding the elements of the subarray that starts at index  index and contains up to  count successive elements.
      ResultSet getResultSet(Map<String,Class<?>> map)
      Retrieves a result set that contains the elements of the SQL  ARRAY value designated by this  Arrayobject.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值