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

The following examples show how to use java.sql.CallableStatement#getBytes() . 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 File: BlobStoredProcedureTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * test the BLOBGETBYTES stored procedure which will
 * be used in the implementation of Blob.getBytes.
 * @throws UnsupportedEncodingException 
 *
 * @throws a SQLException.
 */
public void testBlobGetBytesSP() throws SQLException, UnsupportedEncodingException {
    // This string represents the substring that is got from the
    // stored procedure
    String testSubStr = testStr.substring(0, 10);
    byte [] testSubBytes = testSubStr.getBytes("US-ASCII");

    //create a callable statement and execute it to call the stored
    //procedure BLOBGETBYTES that will get the bytes
    //inserted into the Blob in the setup method.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, 1);
    cs.setLong(3, 1);
    //set the length of the bytes returned as 10.
    cs.setInt(4, 10);
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);

    for (int i=0;i<10;i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , testSubBytes[i], retVal[i]);
    }
    cs.close();
}
 
Example 2
Source File: BlobStoredProcedureTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * test the BLOBGETBYTES stored procedure which will
 * be used in the implementation of Blob.getBytes.
 * @throws UnsupportedEncodingException 
 *
 * @throws a SQLException.
 */
public void testBlobGetBytesSP() throws SQLException, UnsupportedEncodingException {
    // This string represents the substring that is got from the
    // stored procedure
    String testSubStr = testStr.substring(0, 10);
    byte [] testSubBytes = testSubStr.getBytes("US-ASCII");

    //create a callable statement and execute it to call the stored
    //procedure BLOBGETBYTES that will get the bytes
    //inserted into the Blob in the setup method.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, 1);
    cs.setLong(3, 1);
    //set the length of the bytes returned as 10.
    cs.setInt(4, 10);
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);

    for (int i=0;i<10;i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , testSubBytes[i], retVal[i]);
    }
    cs.close();
}
 
Example 3
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
          byte[] i = statement.getBytes(fieldSQL);
          if (statement.wasNull()) {
              ((ByteDataField) field).setValue((Object)null);
          } else {
              ((ByteDataField) field).setValue(i);
          }
      }
 
Example 4
Source File: BlobStoredProcedureTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * test the BLOBGETBYTES stored procedure which will
 * be used in the implementation of Blob.getBytes.
 * @throws UnsupportedEncodingException 
 *
 * @throws a SQLException.
 */
public void testBlobGetBytesSP() throws SQLException, UnsupportedEncodingException {
    // This string represents the substring that is got from the
    // stored procedure
    String testSubStr = testStr.substring(0, 10);
    byte [] testSubBytes = testSubStr.getBytes("US-ASCII");

    //create a callable statement and execute it to call the stored
    //procedure BLOBGETBYTES that will get the bytes
    //inserted into the Blob in the setup method.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, 1);
    cs.setLong(3, 1);
    //set the length of the bytes returned as 10.
    cs.setInt(4, 10);
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);

    for (int i=0;i<10;i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , testSubBytes[i], retVal[i]);
    }
    cs.close();
}
 
Example 5
Source File: ByteObjectArrayTypeHandler.java    From tangyuan2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Byte[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
	byte[] bytes = cs.getBytes(columnIndex);
	return getBytes(bytes);
}
 
Example 6
Source File: ByteArrayTypeHandler.java    From tangyuan2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public byte[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
	return cs.getBytes(columnIndex);
}
 
Example 7
Source File: BlobStoredProcedureTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the stored procedure SYSIBM.BLOBSETBYTES
 * @throws UnsupportedEncodingException 
 *
 * @throws SQLException.
 */
public void testBlobSetBytes() throws SQLException, UnsupportedEncodingException {
    String newString = "123456789012345";
    byte [] newBytes = newString.getBytes("US-ASCII");
    //initialize the locator to a default value.
    int locator = -1;
    //call the stored procedure to return the created locator.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBCREATELOCATOR()");
    cs.registerOutParameter(1, java.sql.Types.INTEGER);
    cs.executeUpdate();
    locator = cs.getInt(1);
    cs.close();

    //use this new locator to test the SETBYTES function
    //by inserting the new bytes and testing whether it has
    //been inserted properly.

    //Insert the new substring.
    cs  = prepareCall("CALL SYSIBM.BLOBSETBYTES(?,?,?,?)");
    cs.setInt(1, locator);
    cs.setLong(2, 1L);
    cs.setInt(3, newString.length());
    cs.setBytes(4, newBytes);
    cs.execute();
    cs.close();

    //check the new locator to see if the value has been inserted correctly.
    cs  = prepareCall("? = CALL " +
        "SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, locator);
    cs.setLong(3, 1);
    cs.setInt(4, newString.length());
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);
    //compare the new bytes and the bytes returned by the stored
    //procedure to see of they are the same.
    for (int i=0;i<newString.length();i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , newBytes[i], retVal[i]);
    }
    cs.close();
}
 
Example 8
Source File: ByteObjectArrayTypeHandler.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public Byte[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  byte[] bytes = cs.getBytes(columnIndex);
  return getBytes(bytes);
}
 
Example 9
Source File: ByteArrayTypeHandler.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getNullableResult(CallableStatement cs, int columnIndex)
    throws SQLException {
  return cs.getBytes(columnIndex);
}
 
Example 10
Source File: BlobStoredProcedureTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the stored procedure SYSIBM.BLOBSETBYTES
 * @throws UnsupportedEncodingException 
 *
 * @throws SQLException.
 */
public void testBlobSetBytes() throws SQLException, UnsupportedEncodingException {
    String newString = "123456789012345";
    byte [] newBytes = newString.getBytes("US-ASCII");
    //initialize the locator to a default value.
    int locator = -1;
    //call the stored procedure to return the created locator.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBCREATELOCATOR()");
    cs.registerOutParameter(1, java.sql.Types.INTEGER);
    cs.executeUpdate();
    locator = cs.getInt(1);
    cs.close();

    //use this new locator to test the SETBYTES function
    //by inserting the new bytes and testing whether it has
    //been inserted properly.

    //Insert the new substring.
    cs  = prepareCall("CALL SYSIBM.BLOBSETBYTES(?,?,?,?)");
    cs.setInt(1, locator);
    cs.setLong(2, 1L);
    cs.setInt(3, newString.length());
    cs.setBytes(4, newBytes);
    cs.execute();
    cs.close();

    //check the new locator to see if the value has been inserted correctly.
    cs  = prepareCall("? = CALL " +
        "SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, locator);
    cs.setLong(3, 1);
    cs.setInt(4, newString.length());
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);
    //compare the new bytes and the bytes returned by the stored
    //procedure to see of they are the same.
    for (int i=0;i<newString.length();i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , newBytes[i], retVal[i]);
    }
    cs.close();
}
 
Example 11
Source File: InnerCallableStatementGetter.java    From hasor with Apache License 2.0 4 votes vote down vote up
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 12
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Object getDbValue(CallableStatement statement)
		throws SQLException {
          byte[] i = statement.getBytes(fieldSQL);
	return statement.wasNull() ? null : i;
}
 
Example 13
Source File: ByteObjectArrayTypeHandler.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public Byte[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  byte[] bytes = cs.getBytes(columnIndex);
  return getBytes(bytes);
}
 
Example 14
Source File: ByteArrayTypeHandler.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getNullableResult(CallableStatement cs, int columnIndex)
    throws SQLException {
  return cs.getBytes(columnIndex);
}
 
Example 15
Source File: BlobStoredProcedureTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Tests the stored procedure SYSIBM.BLOBSETBYTES
 * @throws UnsupportedEncodingException 
 *
 * @throws SQLException.
 */
public void testBlobSetBytes() throws SQLException, UnsupportedEncodingException {
    String newString = "123456789012345";
    byte [] newBytes = newString.getBytes("US-ASCII");
    //initialize the locator to a default value.
    int locator = -1;
    //call the stored procedure to return the created locator.
    CallableStatement cs  = prepareCall
        ("? = CALL SYSIBM.BLOBCREATELOCATOR()");
    cs.registerOutParameter(1, java.sql.Types.INTEGER);
    cs.executeUpdate();
    locator = cs.getInt(1);
    cs.close();

    //use this new locator to test the SETBYTES function
    //by inserting the new bytes and testing whether it has
    //been inserted properly.

    //Insert the new substring.
    cs  = prepareCall("CALL SYSIBM.BLOBSETBYTES(?,?,?,?)");
    cs.setInt(1, locator);
    cs.setLong(2, 1L);
    cs.setInt(3, newString.length());
    cs.setBytes(4, newBytes);
    cs.execute();
    cs.close();

    //check the new locator to see if the value has been inserted correctly.
    cs  = prepareCall("? = CALL " +
        "SYSIBM.BLOBGETBYTES(?,?,?)");
    cs.registerOutParameter(1, java.sql.Types.VARBINARY);
    cs.setInt(2, locator);
    cs.setLong(3, 1);
    cs.setInt(4, newString.length());
    cs.executeUpdate();
    byte [] retVal = cs.getBytes(1);
    //compare the new bytes and the bytes returned by the stored
    //procedure to see of they are the same.
    for (int i=0;i<newString.length();i++){
        assertEquals
            ("The Stored procedure SYSIBM.BLOBGETBYTES " +
            "returns the wrong bytes"
            , newBytes[i], retVal[i]);
    }
    cs.close();
}