本文整理汇总了Java中org.hsqldb.types.Type.convertJavaToSQL方法的典型用法代码示例。如果您正苦于以下问题:Java Type.convertJavaToSQL方法的具体用法?Java Type.convertJavaToSQL怎么用?Java Type.convertJavaToSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hsqldb.types.Type
的用法示例。
在下文中一共展示了Type.convertJavaToSQL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createArrayOf
import org.hsqldb.types.Type; //导入方法依赖的package包/类
/**
* Factory method for creating Array objects.
* <p>
* <b>Note: </b>When <code>createArrayOf</code> is used to create an array object
* that maps to a primitive data type, then it is implementation-defined
* whether the <code>Array</code> object is an array of that primitive
* data type or an array of <code>Object</code>.
* <p>
* <b>Note: </b>The JDBC driver is responsible for mapping the elements
* <code>Object</code> array to the default JDBC SQL type defined in
* java.sql.Types for the given class of <code>Object</code>. 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 <code>SQLException</code> 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 <code>Array.getBaseTypeName</code>
* @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);
}
示例2: setArray
import org.hsqldb.types.Type; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>java.sql.Array</code> object.
* The driver converts this to an SQL <code>ARRAY</code> value when it
* sends it to the database.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* From version 2.0, HSQLDB supports the SQL ARRAY type.
*
* </div>
* <!-- end release-specific documentation -->
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code> value
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since JDK 1.2 (JDK 1.1.x developers: read the overview for
* JDBCParameterMetaData)
*/
public synchronized void setArray(int parameterIndex,
Array x) throws SQLException {
checkParameterIndex(parameterIndex);
Type type = this.parameterMetaData.columnTypes[parameterIndex - 1];
if (!type.isArrayType()) {
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
if (x == null) {
setParameter(parameterIndex, null);
return;
}
Object[] data = null;
if (x instanceof JDBCArray) {
data = ((JDBCArray) x).getArrayInternal();
} else {
Object object = x.getArray();
if (object instanceof Object[]) {
Type baseType = type.collectionBaseType();
Object[] array = (Object[]) object;
data = new Object[array.length];
for (int i = 0; i < data.length; i++) {
data[i] = baseType.convertJavaToSQL(session, array[i]);
}
} else {
// if foreign data is not Object[]
throw JDBCUtil.notSupported();
}
}
parameterValues[parameterIndex - 1] = data;
parameterSet[parameterIndex - 1] = Boolean.TRUE;
}
示例3: setArray
import org.hsqldb.types.Type; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>java.sql.Array</code> object.
* The driver converts this to an SQL <code>ARRAY</code> value when it
* sends it to the database.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* From version 2.0, HSQLDB supports the SQL ARRAY type.
*
* </div>
* <!-- end release-specific documentation -->
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code> value
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since JDK 1.2 (JDK 1.1.x developers: read the overview for
* JDBCParameterMetaData)
*/
public synchronized void setArray(int parameterIndex,
Array x) throws SQLException {
checkParameterIndex(parameterIndex);
Type type = this.parameterMetaData.columnTypes[parameterIndex - 1];
if (!type.isArrayType()) {
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
if (x == null) {
setParameter(parameterIndex, null);
return;
}
Object[] data = null;
if (x instanceof JDBCArray) {
data = (Object[]) ((JDBCArray) x).getArrayInternal();
} else {
Object object = x.getArray();
if (object instanceof Object[]) {
Type baseType = type.collectionBaseType();
Object[] array = (Object[]) object;
data = new Object[array.length];
for (int i = 0; i < data.length; i++) {
data[i] = baseType.convertJavaToSQL(session, array[i]);
}
} else {
// if foreign data is not Object[]
throw JDBCUtil.notSupported();
}
}
parameterValues[parameterIndex - 1] = data;
parameterSet[parameterIndex - 1] = Boolean.TRUE;
}