Java SQL Type getCharStream(Object value, int columnType)

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

Description

get Char Stream

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.*;

import java.nio.charset.*;

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

        // check for NULL
        if (value == null) {
            return null;
        }/*from   w w w.  j av  a 2 s .c om*/

        if (isBinary(columnType)) {
            charStream = new ByteArrayInputStream((byte[]) value);
        } else if (isString(columnType)) {
            charStream = new ByteArrayInputStream(value.toString().getBytes(StandardCharsets.UTF_8));
        } else {
            throw new Exception(
                    "charStream conversion failed. (" + value.toString().trim() + "/" + columnType + ")");
        }

        return charStream;
    }

    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;
        }
    }

    public static byte[] getBytes(Object value, int columnType) throws Exception {
        return (byte[]) (value);
    }
}

Related

  1. getBinary(Object value, int columnType)
  2. getBinaryStream(Object value, int columnType)
  3. getBIRTDataType(Integer datatype)
  4. getCallableStatementValue(CallableStatement cstm, int index)
  5. getCastExpression(Class aClass)
  6. getClass(int sqlType, int precision, int scale)
  7. getClassByJdbcType(int type, int decimalDigits)
  8. getCloverTypeFromJdbcType(int jdbcDataType)
  9. getColumeTypeDesc(Class clazz)