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

The following examples show how to use java.sql.CallableStatement#getBoolean() . 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
Source Project: uavstack   File: DAOFactory.java    License: Apache License 2.0 5 votes vote down vote up
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {

            boolean b = cs.getBoolean(columnIndex);
            if (cs.wasNull()) {
                return null;
            }
            else {
                return new Boolean(b);
            }
        }
 
Example 2
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	boolean b = statement.getBoolean(fieldSQL);
	if (statement.wasNull()) {
		field.setValue((Object)null);
	}else{
		field.setValue(b);	
	}
	
}
 
Example 3
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 4
/**
 * Returns the value of the OUT parameter for a CallableStatement using  parameter index.
 * @param callableStatement
 * @param outParamIndex
 * @param paramType
 * @return
 * @throws SQLException
 */
public static String callableStatementGetStringValue(CallableStatement callableStatement, int outParamIndex,
        String paramType) throws SQLException {

    String outParamValue = null;

    if (paramType.equalsIgnoreCase(AceQLTypes.CHAR) || paramType.equalsIgnoreCase(AceQLTypes.CHARACTER)
    	|| paramType.equalsIgnoreCase(AceQLTypes.VARCHAR)) {
        outParamValue = callableStatement.getString(outParamIndex);
    } else if (paramType.equalsIgnoreCase(AceQLTypes.DECIMAL) || paramType.equalsIgnoreCase(AceQLTypes.NUMERIC)) {

        outParamValue = "" + callableStatement.getBigDecimal(outParamIndex);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.BIT)) {

        outParamValue = "" + callableStatement.getBoolean(outParamIndex);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TINYINT) || paramType.equalsIgnoreCase(AceQLTypes.SMALLINT)
    	|| paramType.equalsIgnoreCase(AceQLTypes.INTEGER)) {

        outParamValue = "" + callableStatement.getInt(outParamIndex);

    }
    // BIGINT Long
    // REAL Float
    // FLOAT Double
    // DOUBLE PRECISION Double
    else if (paramType.equalsIgnoreCase(AceQLTypes.BIGINT)) {

        outParamValue = "" + callableStatement.getLong(outParamIndex);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.REAL)) {

        outParamValue = "" + callableStatement.getFloat(outParamIndex);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.FLOAT)
    	|| paramType.equalsIgnoreCase(AceQLTypes.DOUBLE_PRECISION)) {

        outParamValue = "" + callableStatement.getDouble(outParamIndex);

    }
    // DATE java.sql.Date
    // TIME java.sql.Time
    // TIMESTAMP java.sql.Timestamp
    // HACK Version 3.2.2: add .getTime() to transport in numeric long format instead of
    // Date formated.
    else if (paramType.equalsIgnoreCase(AceQLTypes.DATE)) {
        if (callableStatement.getDate(outParamIndex) != null) {
            outParamValue = "" + callableStatement.getDate(outParamIndex).getTime(); 
        }
        else {
    	outParamValue = null;
        }

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TIME)) { 
        
        if (callableStatement.getTime(outParamIndex) != null) {
            outParamValue = "" + callableStatement.getTime(outParamIndex).getTime(); 
        }
        else {
    	outParamValue = null;
        }

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TIMESTAMP)) {
        
        if (callableStatement.getTimestamp(outParamIndex) != null) {
            outParamValue = "" + callableStatement.getTimestamp(outParamIndex).getTime(); 
        }
        else {
    	outParamValue = null;
        }
        
        
    } else if (paramType.equalsIgnoreCase(AceQLTypes.URL)) {

        outParamValue = "" + callableStatement.getURL(outParamIndex);

    } else {
        throw new IllegalArgumentException(
    	    "Invalid OUT parameter type: " + paramType + " for parameter index " + outParamIndex + ".");
    }
    return outParamValue;
}
 
Example 5
/**
 * Returns the value of the OUT parameter for a CallableStatement using parameter name.
 * @param callableStatement
 * @param outParameterName
 * @param paramType
 * @return
 * @throws SQLException
 */
public static String callableStatementGetStringValue(CallableStatement callableStatement, String outParameterName,
        String paramType) throws SQLException {

    String outParamValue = null;

    if (paramType.equalsIgnoreCase(AceQLTypes.CHAR) || paramType.equalsIgnoreCase(AceQLTypes.CHARACTER)
    	|| paramType.equalsIgnoreCase(AceQLTypes.VARCHAR)) {
        outParamValue = callableStatement.getString(outParameterName);
    } else if (paramType.equalsIgnoreCase(AceQLTypes.DECIMAL) || paramType.equalsIgnoreCase(AceQLTypes.NUMERIC)) {

        outParamValue = "" + callableStatement.getBigDecimal(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.BIT)) {

        outParamValue = "" + callableStatement.getBoolean(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TINYINT) || paramType.equalsIgnoreCase(AceQLTypes.SMALLINT)
    	|| paramType.equalsIgnoreCase(AceQLTypes.INTEGER)) {

        outParamValue = "" + callableStatement.getInt(outParameterName);

    }
    // BIGINT Long
    // REAL Float
    // FLOAT Double
    // DOUBLE PRECISION Double
    else if (paramType.equalsIgnoreCase(AceQLTypes.BIGINT)) {

        outParamValue = "" + callableStatement.getLong(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.REAL)) {

        outParamValue = "" + callableStatement.getFloat(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.FLOAT)
    	|| paramType.equalsIgnoreCase(AceQLTypes.DOUBLE_PRECISION)) {

        outParamValue = "" + callableStatement.getDouble(outParameterName);

    }
    // DATE java.sql.Date
    // TIME java.sql.Time
    // TIMESTAMP java.sql.Timestamp
    else if (paramType.equalsIgnoreCase(AceQLTypes.DATE)) {
        outParamValue = "" + callableStatement.getDate(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TIME)) {
        outParamValue = "" + callableStatement.getTime(outParameterName);

    } else if (paramType.equalsIgnoreCase(AceQLTypes.TIMESTAMP)) {
        outParamValue = "" + callableStatement.getTimestamp(outParameterName);
    } else if (paramType.equalsIgnoreCase(AceQLTypes.URL)) {

        outParamValue = "" + callableStatement.getURL(outParameterName);

    } else {
        throw new IllegalArgumentException(
    	    "Invalid OUT parameter type: " + paramType + " for parameter index " + outParameterName + ".");
    }
    return outParamValue;
}
 
Example 6
public void testBitSp() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

    Boolean minBooleanVal;
    Boolean oRetVal;

    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    //String sMaxBooleanVal = "1";
    // sMaxBooleanVal = "true";
    //Boolean bool = Boolean.valueOf("true");
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    System.out.println("register the output parameters");
    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    System.out.println("execute the procedure");
    cstmt.executeUpdate();

    System.out.println("invoke getBoolean method");
    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    if (oRetVal.equals(minBooleanVal)) {
        System.out.println("getBoolean returns the Minimum value ");
    } else {
        System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

    }
}
 
Example 7
@Override
public Boolean getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
	return cs.getBoolean(columnIndex);
}
 
Example 8
public void testBitSp() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

    Boolean minBooleanVal;
    Boolean oRetVal;

    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    //String sMaxBooleanVal = "1";
    // sMaxBooleanVal = "true";
    //Boolean bool = Boolean.valueOf("true");
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    System.out.println("register the output parameters");
    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    System.out.println("execute the procedure");
    cstmt.executeUpdate();

    System.out.println("invoke getBoolean method");
    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    if (oRetVal.equals(minBooleanVal)) {
        System.out.println("getBoolean returns the Minimum value ");
    } else {
        System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

    }
}
 
Example 9
@Override
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
    return cs.getBoolean(columnIndex);
}
 
Example 10
Source Project: mybaties   File: BooleanTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Boolean getNullableResult(CallableStatement cs, int columnIndex)
    throws SQLException {
  return cs.getBoolean(columnIndex);
}
 
Example 11
public void testBitSp() throws Exception {

        createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

        createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
                + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

        Boolean minBooleanVal;
        Boolean oRetVal;

        String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
        //String sMaxBooleanVal = "1";
        // sMaxBooleanVal = "true";
        //Boolean bool = Boolean.valueOf("true");
        String Min_Insert = "insert into Bit_Tab values(1,0,null)";
        // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
        CallableStatement cstmt;

        this.stmt.executeUpdate("delete from Bit_Tab");
        this.stmt.executeUpdate(Min_Insert);
        cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

        System.out.println("register the output parameters");
        cstmt.registerOutParameter(1, java.sql.Types.BIT);
        cstmt.registerOutParameter(2, java.sql.Types.BIT);
        cstmt.registerOutParameter(3, java.sql.Types.BIT);

        System.out.println("execute the procedure");
        cstmt.executeUpdate();

        System.out.println("invoke getBoolean method");
        boolean bRetVal = cstmt.getBoolean(2);
        oRetVal = new Boolean(bRetVal);
        minBooleanVal = new Boolean("false");
        this.rs = this.stmt.executeQuery(Min_Val_Query);
        if (oRetVal.equals(minBooleanVal)) {
            System.out.println("getBoolean returns the Minimum value ");
        } else {
            System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

        }
    }
 
Example 12
public static Object getValue(final CallableStatement cs, final int index, Class<?> requiredType) throws SQLException {
    Object value = null;
    boolean wasNullCheck = false;
    if (requiredType == null) {
        return cs.getObject(index);
    }
    requiredType = primitiveToWrapper(requiredType);
    // Explicitly extract typed value, as far as possible.
    if (String.class.equals(requiredType)) {
        value = cs.getString(index);
    } else if (Integer.class.equals(requiredType)) {
        value = cs.getInt(index);
        wasNullCheck = true;
    } else if (Double.class.equals(requiredType)) {
        value = cs.getDouble(index);
        wasNullCheck = true;
    } else if (Boolean.class.equals(requiredType)) {
        value = cs.getBoolean(index) ? Boolean.TRUE : Boolean.FALSE;
        wasNullCheck = true;
    } else if (java.sql.Date.class.equals(requiredType)) {
        value = cs.getDate(index);
    } else if (java.sql.Time.class.equals(requiredType)) {
        value = cs.getTime(index);
    } else if (java.sql.Timestamp.class.equals(requiredType)) {
        value = cs.getTimestamp(index);
    } else if (java.util.Date.class.equals(requiredType)) {
        value = new java.util.Date(cs.getTimestamp(index).getTime());
    } else if (Byte.class.equals(requiredType)) {
        value = cs.getByte(index);
        wasNullCheck = true;
    } else if (Short.class.equals(requiredType)) {
        value = cs.getShort(index);
        wasNullCheck = true;
    } else if (Long.class.equals(requiredType)) {
        value = cs.getLong(index);
        wasNullCheck = true;
    } else if (Float.class.equals(requiredType)) {
        value = cs.getFloat(index);
        wasNullCheck = true;
    } else if (Number.class.equals(requiredType)) {
        value = cs.getDouble(index);
        wasNullCheck = true;
    } else if (byte[].class.equals(requiredType)) {
        value = cs.getBytes(index);
    } else if (java.math.BigDecimal.class.equals(requiredType)) {
        value = cs.getBigDecimal(index);
    } else if (java.sql.Blob.class.equals(requiredType)) {
        value = cs.getBlob(index);
    } else if (java.sql.Clob.class.equals(requiredType)) {
        value = cs.getClob(index);
    } else if (java.net.URL.class.equals(requiredType)) {
        value = cs.getURL(index);
    } else {
        // Some unknown type desired -> rely on getObject.
        value = cs.getObject(index);
    }
    // Perform was-null check if demanded (for results that the JDBC driver returns as primitives).
    if (wasNullCheck && value != null && cs.wasNull()) {
        value = null;
    }
    return value;
}
 
Example 13
@Override
public Object getDbValue(CallableStatement statement)
		throws SQLException {
	boolean b = statement.getBoolean(fieldSQL);
	return statement.wasNull() ? null : b;
}
 
Example 14
Source Project: mybatis   File: BooleanTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Boolean getNullableResult(CallableStatement cs, int columnIndex)
    throws SQLException {
  return cs.getBoolean(columnIndex);
}