Java SQL Type getCallableStatementValue(CallableStatement cstm, int index)

Here you can find the source of getCallableStatementValue(CallableStatement cstm, int index)

Description

Gets the callable statement value.

License

Open Source License

Parameter

Parameter Description
cstm the cstm
index the index

Exception

Parameter Description
SQLException the sQL exception

Return

the callable statement value

Declaration

public static Object getCallableStatementValue(CallableStatement cstm, int index) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;

import java.sql.SQLException;

public class Main {
    /**/*from   www  . ja v  a 2 s. co m*/
     * Gets the callable statement value.
     *
     * @param cstm
     *            the cstm
     * @param index
     *            the index
     * @return the callable statement value
     * @throws SQLException
     *             the sQL exception
     */
    public static Object getCallableStatementValue(CallableStatement cstm, int index) throws SQLException {
        Object obj = cstm.getObject(index);
        if (obj instanceof Blob) {
            obj = cstm.getBytes(index);
        } else if (obj instanceof Clob) {
            obj = cstm.getString(index);
        } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.TIMESTAMP")) {
            obj = cstm.getTimestamp(index);
        } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.DATE")) {
            String metaDataClassName = cstm.getMetaData().getColumnClassName(index);
            if ("java.sql.Timestamp".equals(metaDataClassName)
                    || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) {
                obj = cstm.getTimestamp(index);
            } else {
                obj = cstm.getDate(index);
            }
        } else if (obj != null && obj instanceof java.sql.Date) {
            if ("java.sql.Timestamp".equals(cstm.getMetaData().getColumnClassName(index))) {
                obj = cstm.getTimestamp(index);
            }
        }
        return obj;
    }

    /**
     * Gets the callable statement value.
     *
     * @param cstm
     *            the cstm
     * @param name
     *            the name
     * @return the callable statement value
     * @throws SQLException
     *             the sQL exception
     */
    public static Object getCallableStatementValue(CallableStatement cstm, String name) throws SQLException {
        Object obj = cstm.getObject(name);
        if (obj instanceof Blob) {
            obj = cstm.getBytes(name);
        } else if (obj instanceof Clob) {
            obj = cstm.getString(name);
        } else if (obj != null) {
            if (obj instanceof java.sql.Timestamp || "java.sql.Timestamp".equals(obj.getClass().getName())) {
                obj = cstm.getTimestamp(name);
            } else if (obj.getClass().getName().startsWith("oracle.sql.TIMESTAMP")) {
                obj = cstm.getTimestamp(name);
            } else if (obj instanceof java.sql.Date || "java.sql.Date".equals(obj.getClass().getName())) {
                obj = cstm.getDate(name);
            }
        }
        return obj;
    }
}

Related

  1. getArgTypes()
  2. getAsciiStream(Object value, int columnType)
  3. getBinary(Object value, int columnType)
  4. getBinaryStream(Object value, int columnType)
  5. getBIRTDataType(Integer datatype)
  6. getCastExpression(Class aClass)
  7. getCharStream(Object value, int columnType)
  8. getClass(int sqlType, int precision, int scale)
  9. getClassByJdbcType(int type, int decimalDigits)