java lob_Java Type.isLobType方法代码示例

该段代码展示了在Java中使用JDBC创建数组对象的过程,涉及到类型转换、错误处理和数据库兼容性问题。方法首先检查连接是否关闭,然后根据指定的SQL类型名和元素创建Array对象,并进行类型转换和限制检查。如果SQL类型名无效或不匹配,可能会抛出SQLException。
摘要由CSDN通过智能技术生成

import org.hsqldb.types.Type; //导入方法依赖的package包/类

/**

* Factory method for creating Array objects.

*

* Note: When createArrayOf is used to create an array object

* that maps to a primitive data type, then it is implementation-defined

* whether the Array object is an array of that primitive

* data type or an array of Object.

*

* Note: The JDBC driver is responsible for mapping the elements

* Object array to the default JDBC SQL type defined in

* java.sql.Types for the given class of Object. The default

* mapping is specified in Appendix B of the JDBC specification. If the

* resulting JDBC type is not the appropriate type for the given typeName then

* it is implementation defined whether an SQLException is

* thrown or the driver supports the resulting conversion.

*

* @param typeName the SQL name of the type the elements of the array map to. The typeName is a

* database-specific name which may be the name of a built-in type, a user-defined type or a standard SQL type supported by this database. This

* is the value returned by Array.getBaseTypeName

* @param elements the elements that populate the returned object

* @return an Array object whose elements map to the specified SQL type

* @throws SQLException if a database error occurs, the JDBC type is not

* appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection

* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this data type

* @since 1.6

*/

//#ifdef JAVA6

public Array createArrayOf(String typeName,

Object[] elements) throws SQLException {

checkClosed();

if (typeName == null) {

throw JDBCUtil.nullArgument();

}

typeName = typeName.toUpperCase();

int typeCode = Type.getTypeNr(typeName);

if (typeCode < 0) {

throw JDBCUtil.invalidArgument(typeName);

}

Type type = Type.getDefaultType(typeCode);

if (type.isArrayType() || type.isLobType() || type.isRowType()) {

throw JDBCUtil.invalidArgument(typeName);

}

Object[] newData = new Object[elements.length];

try {

for (int i = 0; i < elements.length; i++) {

Object o = type.convertJavaToSQL(sessionProxy, elements[i]);

newData[i] = type.convertToTypeLimits(sessionProxy, o);

}

} catch (HsqlException e) {

throw JDBCUtil.sqlException(e);

}

return new JDBCArray(newData, type, this);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值