Example usage for java.sql CallableStatement getConnection

List of usage examples for java.sql CallableStatement getConnection

Introduction

In this page you can find the example usage for java.sql CallableStatement getConnection.

Prototype

Connection getConnection() throws SQLException;

Source Link

Document

Retrieves the Connection object that produced this Statement object.

Usage

From source file:io.lightlink.oracle.OracleStructArrayType.java

@Override
public Object readFromCallableStatement(CallableStatement cs, int pos, RunnerContext runnerContext,
        String colName) throws SQLException, IOException {

    Array array = cs.getArray(pos);
    return getDataFromArray(unwrap(cs.getConnection()), array);
}

From source file:it.greenvulcano.gvesb.datahandling.dbo.DBOCallSP.java

/**
 * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
 *      java.lang.String, java.lang.String)
 *//*from  ww  w .  j a  va2s . c om*/
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (ROW_NAME.equals(localName)) {
        if (!currCriticalError) {
            executeStatement();
        } else {
            rowDisc++;
            // aggiunta DiscardCause al dhr...
            String msg = currentXSLMessage;

            dhr.addDiscardCause(new DiscardCause(rowCounter, msg));

            resultMessage.append("Data error on row ").append(rowCounter).append(": ").append(msg);
            resultMessage.append("SQL Statement Informations:\n").append(sqlStatementInfo);
            resultMessage.append("Record parameters:\n").append(dumpCurrentRowFields());
            resultStatus = STATUS_PARTIAL;
        }
    } else if (COL_NAME.equals(localName)) {
        CallableStatement cs = (CallableStatement) sqlStatementInfo.getStatement();
        try {
            if (!outOnly) {
                colDataExpecting = false;
                String text = textBuffer.toString();
                if ((currentUUID != null) && (currentUUID.trim().length() > 0) && (text.length() == 0)) {
                    text = uuids.get(currentUUID);
                    if (text == null) {
                        text = currentUUID;
                    }
                }
                if (TIMESTAMP_TYPE.equals(currType) || DATE_TYPE.equals(currType)
                        || TIME_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (TIMESTAMP_TYPE.equals(currType))
                            setNull(cs, Types.TIMESTAMP);
                        else if (DATE_TYPE.equals(currType))
                            setNull(cs, Types.DATE);
                        else
                            setNull(cs, Types.TIME);
                        currentRowFields.add(null);
                    } else {
                        dateFormatter.applyPattern(currDateFormat);
                        Date formattedDate = dateFormatter.parse(text);
                        if (TIMESTAMP_TYPE.equals(currType)) {
                            Timestamp ts = new Timestamp(formattedDate.getTime());
                            setTimestamp(cs, ts);
                            currentRowFields.add(ts);
                        } else if (DATE_TYPE.equals(currType)) {
                            java.sql.Date d = new java.sql.Date(formattedDate.getTime());
                            setDate(cs, d);
                            currentRowFields.add(d);
                        } else {
                            java.sql.Time t = new java.sql.Time(formattedDate.getTime());
                            setTime(cs, t);
                            currentRowFields.add(t);
                        }
                    }
                } else if (INTEGER_TYPE.equals(currType) || SMALLINT_TYPE.equals(currType)
                        || BIGINT_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (INTEGER_TYPE.equals(currType))
                            setNull(cs, Types.INTEGER);
                        else if (SMALLINT_TYPE.equals(currType))
                            setNull(cs, Types.SMALLINT);
                        else
                            setNull(cs, Types.BIGINT);
                        currentRowFields.add(null);
                    } else {
                        if (INTEGER_TYPE.equals(currType))
                            setInt(cs, Integer.parseInt(text, 10));
                        else if (SMALLINT_TYPE.equals(currType))
                            setShort(cs, Short.parseShort(text, 10));
                        else
                            setLong(cs, Long.parseLong(text, 10));
                        currentRowFields.add(text);
                    }
                } else if (FLOAT_TYPE.equals(currType) || DOUBLE_TYPE.equals(currType)
                        || DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType))
                            setNull(cs, Types.NUMERIC);
                        else if (FLOAT_TYPE.equals(currType))
                            setNull(cs, Types.FLOAT);
                        else
                            setNull(cs, Types.DOUBLE);
                        currentRowFields.add(null);
                    } else {
                        DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
                        dfs.setDecimalSeparator(currDecSeparator.charAt(0));
                        dfs.setGroupingSeparator(currGroupSeparator.charAt(0));
                        numberFormatter.setDecimalFormatSymbols(dfs);
                        numberFormatter.applyPattern(currNumberFormat);
                        boolean isBigDecimal = numberFormatter.isParseBigDecimal();
                        try {
                            numberFormatter.setParseBigDecimal(true);
                            BigDecimal formattedNumber = (BigDecimal) numberFormatter.parse(text);
                            if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                                setBigDecimal(cs, formattedNumber);
                                currentRowFields.add(formattedNumber);
                            } else if (FLOAT_TYPE.equals(currType)) {
                                setFloat(cs, formattedNumber.floatValue());
                                currentRowFields.add(formattedNumber.floatValue());
                            } else {
                                setDouble(cs, formattedNumber.doubleValue());
                                currentRowFields.add(formattedNumber.doubleValue());
                            }
                        } finally {
                            numberFormatter.setParseBigDecimal(isBigDecimal);
                        }
                    }
                } else if (LONG_STRING_TYPE.equals(currType) || LONG_NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (LONG_STRING_TYPE.equals(currType))
                            setNull(cs, Types.CLOB);
                        else
                            setNull(cs, Types.NCLOB);
                        currentRowFields.add(null);
                    } else {
                        if (LONG_STRING_TYPE.equals(currType)) {
                            setCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        } else {
                            setNCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        }
                    }
                } else if (BASE64_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        data = Base64.getDecoder().decode(data);
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BINARY_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BOOLEAN_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BOOLEAN);
                        currentRowFields.add(null);
                    } else {
                        setBoolean(cs, TextUtils.parseBoolean(text));
                        currentRowFields.add(text);
                    }
                } else if (XML_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.SQLXML);
                        currentRowFields.add(null);
                    } else {
                        SQLXML xml = cs.getConnection().createSQLXML();
                        xml.setString(text);
                        setSQLXML(cs, xml);
                        currentRowFields.add(text);
                    }
                } else if (NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.NVARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setNString(cs, text);
                        currentRowFields.add(text);
                    }
                } else {
                    if (text.equals("")) {
                        setNull(cs, Types.VARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setString(cs, text);
                        currentRowFields.add(text);
                    }
                }
            } else {
                currentRowFields.add(currentUUID);
            }
        } catch (ParseException exc) {
            throw new SAXException(exc);
        } catch (SQLException exc) {
            OracleExceptionHandler.handleSQLException(exc);
            throw new SAXException(exc);
        }
    }
}

From source file:org.openbravo.database.ConnectionProviderImpl.java

public void releaseCallableStatement(CallableStatement callableStatement) throws SQLException {
    if (callableStatement == null)
        return;//w  w w . ja v a 2 s .  co  m
    Connection conn = null;
    try {
        conn = callableStatement.getConnection();
        callableStatement.close();
        releaseConnection(conn);
    } catch (SQLException e) {
        log4j.error("releaseCallableStatement: " + e);
        releaseConnection(conn);
        throw e;
    }
}

From source file:org.xsystem.sql2.dml.DmlCommand.java

void setParms(CallableStatement cs, List<DmlParams> paramsSpec, Map<String, Object> values)
        throws SQLException {
    int i = 0;// www  .j  a  v  a 2  s . co  m
    Connection con = cs.getConnection();
    AbstactNativeHelper nativeHelper = nativeHelperFactory(con);
    for (DmlParams row : paramsSpec) {
        String paramName = row.getName();
        Integer jdbcType = row.getJdbcType();
        String objectType = row.getObjectType();
        Object value = values.get(paramName);
        boolean in = row.isIn();
        boolean out = row.isOut();
        i = i + 1;
        if (in) {
            if (namedParams) {
                if (jdbcType == Types.OTHER) {
                    cs.setObject(paramName, value);
                } else {
                    value = setValue(value, jdbcType, objectType, con, nativeHelper);
                    if (value != null) {
                        value = convert(value, jdbcType);
                        cs.setObject(paramName, value, jdbcType);
                    } else {
                        cs.setNull(paramName, jdbcType);
                    }
                }
            } else {
                if (jdbcType == Types.OTHER) {
                    cs.setObject(i, value);
                } else {
                    if (jdbcType == JdbcTypeMapping.json) {
                        nativeHelper.setJSONPARAM(cs, i, value);
                    } else {
                        value = setValue(value, jdbcType, objectType, con, nativeHelper);

                        if (value != null) {
                            value = convert(value, jdbcType);
                            cs.setObject(i, value, jdbcType);
                        } else {
                            cs.setNull(i, jdbcType);
                        }
                    }
                }
            }
        }
        if (out) {
            if (namedParams) {

                if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) {
                    cs.registerOutParameter(paramName, jdbcType, objectType);
                } else {
                    cs.registerOutParameter(paramName, jdbcType);
                }

            } else {
                if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) {
                    cs.registerOutParameter(i, jdbcType, objectType);
                } else {
                    cs.registerOutParameter(i, jdbcType);
                }
            }
        }
    }
}

From source file:org.xsystem.sql2.dml.DmlCommand.java

Map buildOutParams(CallableStatement cs, List<DmlParams> paramsSpec) throws SQLException {
    Map ret = null;/*from   w  ww  .j a va2 s .  com*/
    Connection con = cs.getConnection();
    AbstactNativeHelper nativeHelper = nativeHelperFactory(con);
    int i = 0;
    for (DmlParams row : paramsSpec) {
        String paramName = row.getName();
        Integer jdbcType = row.getJdbcType();
        String objectType = row.getObjectType();
        boolean out = row.isOut();
        i = i + 1;
        if (out) {
            if (ret == null) {
                ret = new LinkedHashMap();
            }
            if (namedParams) {
                Object retValue = cs.getObject(paramName);
                retValue = getValue(retValue, jdbcType, objectType, con, nativeHelper);

                ret.put(paramName, retValue);
            } else {
                Object retValue = cs.getObject(i);
                if (Auxilary.isEmptyOrNull(paramName)) {
                    paramName = "" + i;
                }
                retValue = getValue(retValue, jdbcType, objectType, con, nativeHelper);
                ret.put(paramName, retValue);
            }
        }
    }
    return ret;
}