Example usage for java.sql CallableStatement getTime

List of usage examples for java.sql CallableStatement getTime

Introduction

In this page you can find the example usage for java.sql CallableStatement getTime.

Prototype

java.sql.Time getTime(String parameterName) throws SQLException;

Source Link

Document

Retrieves the value of a JDBC TIME parameter as a java.sql.Time object.

Usage

From source file:com.netspective.axiom.sql.StoredProcedureParameter.java

/**
 * Extract the OUT parameter values from the callable statment and
 * assign them to the value of the parameter.
 */// ww  w .  j  a  va  2  s.c  o m
public void extract(ConnectionContext cc, CallableStatement stmt) throws SQLException {
    if (getType().getValueIndex() == StoredProcedureParameter.Type.IN)
        return;

    int index = this.getIndex();
    QueryParameterType paramType = getSqlType();
    int jdbcType = paramType.getJdbcType();
    String identifier = paramType.getIdentifier();

    // result sets are special
    if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER)) {
        ResultSet rs = (ResultSet) stmt.getObject(index);
        QueryResultSet qrs = new QueryResultSet(getParent().getProcedure(), cc, rs);
        value.getValue(cc).setValue(qrs);
        return;
    }

    switch (jdbcType) {
    case Types.VARCHAR:
        value.getValue(cc).setTextValue(stmt.getString(index));
        break;
    case Types.INTEGER:
        value.getValue(cc).setValue(new Integer(stmt.getInt(index)));
        break;
    case Types.DOUBLE:
        value.getValue(cc).setValue(new Double(stmt.getDouble(index)));
        break;
    case Types.CLOB:
        Clob clob = stmt.getClob(index);
        value.getValue(cc).setTextValue(clob.getSubString(1, (int) clob.length()));
        break;
    case java.sql.Types.ARRAY:
        Array array = stmt.getArray(index);
        value.getValue(cc).setValue(array);
        break;
    case java.sql.Types.BIGINT:
        long bigint = stmt.getLong(index);
        value.getValue(cc).setValue(new Long(bigint));
        break;
    case java.sql.Types.BINARY:
        value.getValue(cc).setTextValue(new String(stmt.getBytes(index)));
        break;
    case java.sql.Types.BIT:
        boolean bit = stmt.getBoolean(index);
        value.getValue(cc).setValue(new Boolean(bit));
    case java.sql.Types.BLOB:
        value.getValue(cc).setValue(stmt.getBlob(index));
        break;
    case java.sql.Types.CHAR:
        value.getValue(cc).setTextValue(stmt.getString(index));
        break;
    case java.sql.Types.DATE:
        value.getValue(cc).setValue(stmt.getDate(index));
        break;
    case java.sql.Types.DECIMAL:
        value.getValue(cc).setValue(stmt.getBigDecimal(index));
        break;
    case java.sql.Types.DISTINCT:
        value.getValue(cc).setValue(stmt.getObject(index));
        break;
    case java.sql.Types.FLOAT:
        value.getValue(cc).setValue(new Float(stmt.getFloat(index)));
        break;
    case java.sql.Types.JAVA_OBJECT:
        value.getValue(cc).setValue(stmt.getObject(index));
        break;
    case java.sql.Types.LONGVARBINARY:
        value.getValue(cc).setTextValue(new String(stmt.getBytes(index)));
        break;
    case java.sql.Types.LONGVARCHAR:
        value.getValue(cc).setTextValue(stmt.getString(index));
        break;
    //case java.sql.Types.NULL:
    //    value.getValue(cc).setValue(null);
    //    break;
    case java.sql.Types.NUMERIC:
        value.getValue(cc).setValue(stmt.getBigDecimal(index));
        break;
    case java.sql.Types.OTHER:
        value.getValue(cc).setValue(stmt.getObject(index));
        break;
    case java.sql.Types.REAL:
        value.getValue(cc).setValue(new Float(stmt.getFloat(index)));
        break;
    //case java.sql.Types.REF:
    //    Ref ref = stmt.getRef(index);
    //    break;
    case java.sql.Types.SMALLINT:
        short sh = stmt.getShort(index);
        value.getValue(cc).setValue(new Short(sh));
        break;
    case java.sql.Types.STRUCT:
        value.getValue(cc).setValue(stmt.getObject(index));
        break;
    case java.sql.Types.TIME:
        value.getValue(cc).setValue(stmt.getTime(index));
        break;
    case java.sql.Types.TIMESTAMP:
        value.getValue(cc).setValue(stmt.getTimestamp(index));
        break;
    case java.sql.Types.TINYINT:
        byte b = stmt.getByte(index);
        value.getValue(cc).setValue(new Byte(b));
        break;
    case java.sql.Types.VARBINARY:
        value.getValue(cc).setValue(stmt.getBytes(index));
        break;
    default:
        throw new RuntimeException(
                "Unknown JDBC Type set for stored procedure parameter '" + this.getName() + "'.");
    }
}

From source file:org.siphon.jssql.SqlExecutor.java

private Object translateOutputParameterValue(int sqlType, CallableStatement cs, int index)
        throws SQLException, SqlExecutorException, ScriptException {
    Object obj = cs.getObject(index);
    if (obj == null) {
        return null;
    } else {//w  ww . j a v  a2s . c  o m
        switch (sqlType) {
        case Types.DATE:
            obj = cs.getDate(index);
        case Types.TIME:
            obj = cs.getTime(index);
        case Types.TIMESTAMP:
            obj = cs.getTimestamp(index);
        }

    }

    Object result = jdbcReturnTypeToJsObject(obj);
    if (result instanceof String) {
        return ((String) result).trim();
    } else {
        return result;
    }
}

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private ParamValue getOutparameterValue(CallableStatement cs, String type, int ordinal)
        throws DataServiceFault {
    try {// w  ww  . ja  v a 2s  .c o  m
        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)) {
            elementValue = cs.getTimestamp(ordinal, calendar);
            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.");
    }
}

From source file:org.wso2.ws.dataservice.DBUtils.java

private static String setOutparameterValue(CallableStatement cs, Query query, String resultSetFieldName)
        throws SQLException, AxisFault {
    // This could be an out parameter
    //Procedure returns both result & out parameters
    String elementValue = "";
    Param param = query.getParam(resultSetFieldName);
    if (param != null) {
        if ("OUT".equals(param.getType()) || "INOUT".equals(param.getType())) {
            if (param.getSqlType().equals(DBConstants.DataTypes.STRING)) {
                elementValue = cs.getString(param.getOrdinal());
            } else if (param.getSqlType().equals(DBConstants.DataTypes.DOUBLE)) {
                elementValue = String.valueOf(cs.getDouble(param.getOrdinal()));
            } else if (param.getSqlType().equals(DBConstants.DataTypes.BIGINT)) {
                elementValue = String.valueOf(cs.getLong(param.getOrdinal()));
            } else if (param.getSqlType().equals(DBConstants.DataTypes.INTEGER)) {
                elementValue = String.valueOf(cs.getInt(param.getOrdinal()));
            } else if (param.getSqlType().equals(DBConstants.DataTypes.TIME)) {
                elementValue = String.valueOf(cs.getTime(param.getOrdinal()));
            } else if (param.getSqlType().equals(DBConstants.DataTypes.DATE)) {
                elementValue = String.valueOf(cs.getDate(param.getOrdinal()));
            } else if (param.getSqlType().equals(DBConstants.DataTypes.TIMESTAMP)) {
                elementValue = String.valueOf(cs.getTimestamp(param.getOrdinal()));
            } else {
                log.error("Unsupported data type : " + param.getSqlType());
                throw new AxisFault("Unsupported data type : " + param.getSqlType());
            }//from   ww w.  j  a va 2 s  .  c  om

        }
    }
    return elementValue;
}