Java SQL Type getBinary(Object value, int columnType)

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

Description

get Binary

License

Open Source License

Declaration

public static String getBinary(Object value, int columnType) throws Exception 

Method Source Code


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

import java.io.*;

import java.sql.*;

public class Main {
    public static String getBinary(Object value, int columnType) throws Exception {
        String result = null;/*ww  w. jav  a2s. co m*/
        InputStream stream = null;
        char[] buffer = new char[1024];

        try {
            if ((columnType == java.sql.Types.BINARY) || (columnType == java.sql.Types.VARBINARY)
                    || (columnType == java.sql.Types.LONGVARBINARY) || (columnType == java.sql.Types.BLOB)) {
                byte[] blobData = ((Blob) value).getBytes(1, (int) ((Blob) value).length());
                result = new String(blobData, "US-ASCII");
            } else if (columnType == java.sql.Types.CLOB) {
                result = ((Clob) value).getSubString(1, (int) ((Clob) value).length());
            } else if ((columnType == java.sql.Types.VARCHAR) || (columnType == java.sql.Types.LONGVARCHAR)) {
                byte[] blobData = ((Blob) value).getBytes(1, (int) ((Blob) value).length());
                result = new String(blobData, "UTF-8");
            }
        } catch (Exception ex) {
            throw new Exception("clob conversion failed. (" + value.toString().trim() + ")");
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (Exception exi) {
                }
            }
        }

        return result;
    }

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

Related

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