Java Code Examples for java.sql.CallableStatement#getArray()

The following examples show how to use java.sql.CallableStatement#getArray() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	Array fieldVal = statement.getArray(fieldSQL);
	Object obj = fieldVal.getArray();

      	Object [] objectArray = (Object []) obj;   // cast it to an array of objects
      	
      	StringBuffer buffer = new StringBuffer("{");
      	buffer.append(String.valueOf(objectArray[0]));
      	for (int j=1; j < objectArray.length; j++)
      	   {
      			buffer.append(", ").append(String.valueOf(objectArray[j]));
      	   }
      	buffer.append("}");
	if (statement.wasNull()) {
		((StringDataField) field).setValue((Object)null);
	} else {
		((StringDataField) field).setValue(buffer.toString());
	}
}
 
Example 2
Source Project: mybatis-types   File: ArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    Array array = cs.getArray(columnIndex);
    if (array == null) {
        return empty();
    }
    return fromArray(array);
}
 
Example 3
Source Project: mmpt   File: TextArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public String[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (String[])outputArray.getArray();
}
 
Example 4
Source Project: mmpt   File: IntegerArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Integer[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (Integer[])outputArray.getArray();
}
 
Example 5
Source Project: mmpt   File: SmallIntArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Integer[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (Integer[])outputArray.getArray();
}
 
Example 6
Source Project: mmpt   File: BooleanArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Boolean[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (Boolean[])outputArray.getArray();
}
 
Example 7
Source Project: mmpt   File: BigIntArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public Long[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (Long[])outputArray.getArray();
}
 
Example 8
Source Project: mmpt   File: UUIDArrayTypeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public UUID[] getNullableResult(CallableStatement cs, int columnIndex)
        throws SQLException {
    Array outputArray = cs.getArray(columnIndex);
    if (outputArray == null) {
        return null;
    }
    return (UUID[])outputArray.getArray();
}
 
Example 9
Source Project: micro-integrator   File: SQLQuery.java    License: Apache License 2.0 4 votes vote down vote up
private ParamValue getOutparameterValue(CallableStatement cs, String type, int ordinal)
        throws DataServiceFault {
    try {
        Object elementValue;
        if (type.equals(DBConstants.DataTypes.STRING)) {
            elementValue = cs.getString(ordinal);
            return new ParamValue(elementValue == null ? null : elementValue.toString());
        } else if (type.equals(DBConstants.DataTypes.DOUBLE)) {
            elementValue = cs.getDouble(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Double) elementValue));
        } else if (type.equals(DBConstants.DataTypes.BIGINT)) {
            elementValue = cs.getLong(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Long) elementValue));
        } else if (type.equals(DBConstants.DataTypes.INTEGER)) {
            elementValue = cs.getInt(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Integer) elementValue));
        } else if (type.equals(DBConstants.DataTypes.TIME)) {
            elementValue = cs.getTime(ordinal);
            return new ParamValue(elementValue == null ? null
                    : this.convertToTimeString((Time) elementValue));
        } else if (type.equals(DBConstants.DataTypes.DATE)) {
            elementValue = cs.getDate(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Date) elementValue));
        } else if (type.equals(DBConstants.DataTypes.TIMESTAMP)) {
            if (timeConvertEnabled) {
                elementValue = cs.getTimestamp(ordinal, calendar);
            } else {
                elementValue = cs.getTimestamp(ordinal);
            }
            return new ParamValue(elementValue == null ? null
                    : this.convertToTimestampString((Timestamp) elementValue));
        } else if (type.equals(DBConstants.DataTypes.BLOB)) {
            elementValue = cs.getBlob(ordinal);
            return new ParamValue(elementValue == null ? null
                    : this.getBase64StringFromInputStream(((Blob) elementValue)
                            .getBinaryStream()));
        } else if (type.equals(DBConstants.DataTypes.CLOB)) {
            elementValue = cs.getClob(ordinal);
            return new ParamValue(elementValue == null ? null :
                   deriveValueFromClob((Clob) elementValue));
        } else if (type.equals(DBConstants.DataTypes.STRUCT)) {
            elementValue = cs.getObject(ordinal);
            return new ParamValue(elementValue == null ? null : (Struct) elementValue);
        } else if (type.equals(DBConstants.DataTypes.ARRAY)) {
            Array dataArray = cs.getArray(ordinal);
            ParamValue paramValue = new ParamValue(ParamValue.PARAM_VALUE_ARRAY);
            if (dataArray != null) {
                this.processSQLArray(dataArray, paramValue);
            }
            return paramValue;
        } else if (type.equals(DBConstants.DataTypes.NUMERIC)) {
            elementValue = cs.getBigDecimal(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((BigDecimal) elementValue));
        } else if (type.equals(DBConstants.DataTypes.BIT)) {
            elementValue = cs.getBoolean(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Boolean) elementValue));
        } else if (type.equals(DBConstants.DataTypes.TINYINT)) {
            elementValue = cs.getByte(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Byte) elementValue));
        } else if (type.equals(DBConstants.DataTypes.SMALLINT)) {
            elementValue = cs.getShort(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Short) elementValue));
        } else if (type.equals(DBConstants.DataTypes.REAL)) {
            elementValue = cs.getFloat(ordinal);
            return new ParamValue(elementValue == null ? null
                    : ConverterUtil.convertToString((Float) elementValue));
        } else if (type.equals(DBConstants.DataTypes.BINARY)) {
            elementValue = cs.getBlob(ordinal);
            return new ParamValue(elementValue == null ? null
                    : this.getBase64StringFromInputStream(((Blob) elementValue)
                            .getBinaryStream()));
        } else {
            throw new DataServiceFault("Unsupported data type: " + type);
        }
    } catch (SQLException e) {
        throw new DataServiceFault(e, "Error in getting sql output parameter values.");
    }
}
 
Example 10
@Override
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
	Array array = cs.getArray(columnIndex);
	return array == null ? null : array.getArray();
}
 
Example 11
Source Project: mybaties   File: ArrayTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  Array array = cs.getArray(columnIndex);
  return array == null ? null : array.getArray();
}
 
Example 12
@Override
public Object getDbValue(CallableStatement statement)
		throws SQLException {
	Array fieldVal = statement.getArray(fieldSQL);
	return statement.wasNull() ? null : fieldVal;
}
 
Example 13
Source Project: mybatis   File: ArrayTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  Array array = cs.getArray(columnIndex);
  return array == null ? null : array.getArray();
}