Java SQL Type getBinaryStream(Object value, int columnType)

Here you can find the source of getBinaryStream(Object value, int columnType)

Description

get Binary Stream

License

Open Source License

Declaration

public static java.io.InputStream getBinaryStream(Object value, int columnType) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static java.io.InputStream getBinaryStream(Object value, int columnType) throws Exception {
        InputStream binaryStream = null;

        // check for NULL
        if (value == null) {
            return null;
        }//  w  ww . j a  v  a2  s  .co m

        if ((isBinary(columnType) == false) && (isString(columnType) == false)) {
            throw new Exception(
                    "binaryStream conversion failed. (" + value.toString().trim() + "/" + columnType + ")");
        }

        binaryStream = new ByteArrayInputStream((byte[]) value);
        return (java.io.InputStream) binaryStream;
    }

    public static boolean isBinary(int dataType) {
        switch (dataType) {
        case java.sql.Types.BLOB:
        case java.sql.Types.CLOB:
        case java.sql.Types.NCLOB:
        case java.sql.Types.BINARY:
        case java.sql.Types.VARBINARY:
        case java.sql.Types.LONGVARBINARY:
        case java.sql.Types.SQLXML:
            return true;
        default:
            return false;
        }
    }

    public static boolean isString(int dataType) {
        switch (dataType) {
        case java.sql.Types.CHAR:
        case java.sql.Types.VARCHAR:
        case java.sql.Types.LONGVARCHAR:
        case java.sql.Types.NCHAR:
        case java.sql.Types.NVARCHAR:
        case java.sql.Types.LONGNVARCHAR:
            return true;
        default:
            return false;
        }
    }
}

Related

  1. findMethod(Class returnType, Class parameterType)
  2. getAntipodeForFunction(String base, int destType)
  3. getArgTypes()
  4. getAsciiStream(Object value, int columnType)
  5. getBinary(Object value, int columnType)
  6. getBIRTDataType(Integer datatype)
  7. getCallableStatementValue(CallableStatement cstm, int index)
  8. getCastExpression(Class aClass)
  9. getCharStream(Object value, int columnType)