Example usage for java.sql SQLXML setString

List of usage examples for java.sql SQLXML setString

Introduction

In this page you can find the example usage for java.sql SQLXML setString.

Prototype

void setString(String value) throws SQLException;

Source Link

Document

Sets the XML value designated by this SQLXML instance to the given String representation.

Usage

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)
 *///w  ww. j a va  2 s  .co  m
@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);
        }
    }
}