Java SQL Type getAsciiStream(Object value, int columnType)

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

Description

get Ascii Stream

License

Open Source License

Declaration

public static java.io.InputStream getAsciiStream(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 getAsciiStream(Object value, int columnType) throws Exception {
        InputStream asciiStream = null;

        // check for NULL
        if (value == null) {
            return null;
        }/*from  ww w  .  j  ava 2s  .  co  m*/

        try {
            if (isString(columnType)) {
                asciiStream = new ByteArrayInputStream(((String) value).getBytes("ASCII"));
            } else {
                throw new Exception(
                        "asciiStream conversion failed. (" + value.toString().trim() + "/" + columnType + ")");
            }
        } catch (java.io.UnsupportedEncodingException ex) {
            throw new Exception(
                    "asciiStream conversion failed. (" + value.toString().trim() + "/" + columnType + ")");
        }

        return (java.io.InputStream) asciiStream;
    }

    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. extractConstant(String typeName)
  2. fillLogParams(String sql, Map logParams)
  3. findMethod(Class returnType, Class parameterType)
  4. getAntipodeForFunction(String base, int destType)
  5. getArgTypes()
  6. getBinary(Object value, int columnType)
  7. getBinaryStream(Object value, int columnType)
  8. getBIRTDataType(Integer datatype)
  9. getCallableStatementValue(CallableStatement cstm, int index)