Example usage for java.sql Types ARRAY

List of usage examples for java.sql Types ARRAY

Introduction

In this page you can find the example usage for java.sql Types ARRAY.

Prototype

int ARRAY

To view the source code for java.sql Types ARRAY.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY.

Usage

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

Object getValue(Object retValue, int jdbcType, String objectType, Connection con,
        AbstactNativeHelper nativeHelper) throws SQLException {
    if (jdbcType == Types.ARRAY && retValue != null) {
        Array array = (Array) retValue;
        retValue = nativeHelper.createList(con, array, objectType);
    } else if (jdbcType == Types.STRUCT && retValue != null) {
        Struct structValue = (Struct) retValue;
        retValue = nativeHelper.createMap(con, structValue, objectType);
    } else if (jdbcType == Types.BLOB && retValue != null) {
        Blob blob = (Blob) retValue;
        retValue = getBlob(blob);//from   w  w w. j a va  2 s.c  o m
    } else if (jdbcType == Types.CLOB && retValue != null) {
        Clob clob = (Clob) retValue;
        retValue = getClob(clob);
    } else if (jdbcType == Types.OTHER && retValue != null) {
        retValue = nativeHelper.getOTHER(con, retValue);
    }
    return retValue;
}

From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java

@Override
public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column)
        throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        String v;/* w  w w  . j a v  a2s .co m*/
        if (column.getType() == ColumnType.BLOBID) {
            v = ((Binary) value).getDigest();
        } else {
            v = (String) value;
        }
        ps.setString(index, v);
        break;
    case Types.BIT:
        ps.setBoolean(index, ((Boolean) value).booleanValue());
        return;
    case Types.SMALLINT:
        ps.setInt(index, ((Long) value).intValue());
        return;
    case Types.INTEGER:
    case Types.BIGINT:
        ps.setLong(index, ((Long) value).longValue());
        return;
    case Types.DOUBLE:
        ps.setDouble(index, ((Double) value).doubleValue());
        return;
    case Types.TIMESTAMP:
        Calendar cal = (Calendar) value;
        Timestamp ts = new Timestamp(cal.getTimeInMillis());
        ps.setTimestamp(index, ts, cal); // cal passed for timezone
        return;
    case Types.ARRAY:
        Array array = createArrayOf(Types.VARCHAR, (Object[]) value, ps.getConnection());
        ps.setArray(index, array);
        return;
    case Types.OTHER:
        if (column.getType() == ColumnType.FTSTORED) {
            ps.setString(index, (String) value);
            return;
        }
        throw new SQLException("Unhandled type: " + column.getType());
    default:
        throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
    }
}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column)
        throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        setToPreparedStatementString(ps, index, value, column);
        return;//from www .  jav  a2 s .co  m
    case Types.BIT:
        ps.setBoolean(index, ((Boolean) value).booleanValue());
        return;
    case Types.SMALLINT:
        ps.setInt(index, ((Long) value).intValue());
        return;
    case Types.INTEGER:
    case Types.BIGINT:
        ps.setLong(index, ((Long) value).longValue());
        return;
    case Types.DOUBLE:
        ps.setDouble(index, ((Double) value).doubleValue());
        return;
    case Types.TIMESTAMP:
        setToPreparedStatementTimestamp(ps, index, value, column);
        return;
    case Types.ARRAY:
        Array array = createArrayOf(Types.VARCHAR, (Object[]) value, ps.getConnection());
        ps.setArray(index, array);
        return;
    case Types.OTHER:
        if (column.getType() == ColumnType.FTSTORED) {
            ps.setString(index, (String) value);
            return;
        }
        throw new SQLException("Unhandled type: " + column.getType());
    default:
        throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
    }
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Get the Statement column so that the results are mapped correctly.
 * (this has been copied from AbstractDatabaseAction and modified slightly)
 *//*from  w  w  w  .  ja  v a 2 s.  c  om*/
public static Object getColumn(ResultSet set, Configuration column) throws Exception {

    Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type"));
    String dbcol = column.getAttribute("name");
    Object value = null;

    switch (type.intValue()) {
    case Types.CLOB:
    case Types.CHAR:
        Clob dbClob = set.getClob(dbcol);
        int length = (int) dbClob.length();
        InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
        byte[] buffer = new byte[length];
        asciiStream.read(buffer);
        String str = new String(buffer);
        asciiStream.close();
        value = str;
        break;
    case Types.BIGINT:
        value = set.getBigDecimal(dbcol);
        break;
    case Types.TINYINT:
        value = new Byte(set.getByte(dbcol));
        break;
    case Types.VARCHAR:
        value = set.getString(dbcol);
        break;
    case Types.DATE:
        value = set.getDate(dbcol);
        break;
    case Types.DOUBLE:
        value = new Double(set.getDouble(dbcol));
        break;
    case Types.FLOAT:
        value = new Float(set.getFloat(dbcol));
        break;
    case Types.INTEGER:
        value = new Integer(set.getInt(dbcol));
        break;
    case Types.NUMERIC:
        value = new Long(set.getLong(dbcol));
        break;
    case Types.SMALLINT:
        value = new Short(set.getShort(dbcol));
        break;
    case Types.TIME:
        value = set.getTime(dbcol);
        break;
    case Types.TIMESTAMP:
        value = set.getTimestamp(dbcol);
        break;
    case Types.ARRAY:
        value = set.getArray(dbcol); // new Integer(set.getInt(dbcol));
        break;
    case Types.BIT:
        value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol));
        break;
    case Types.STRUCT:
        value = (Struct) set.getObject(dbcol);
        break;
    case Types.OTHER:
        value = set.getObject(dbcol);
        break;

    default:
        // The blob types have to be requested separately, via a Reader.
        value = "";
        break;
    }

    return value;
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING://from w  ww .  ja  v a  2  s .c om
        if (type.isUnconstrained()) {
            return jdbcInfo("varchar", Types.VARCHAR);
        } else if (type.isClob()) {
            return jdbcInfo("text", Types.CLOB);
        } else {
            return jdbcInfo("varchar(%d)", type.length, Types.VARCHAR);
        }
    case ARRAY_STRING:
        if (type.isUnconstrained()) {
            return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR);
        } else if (type.isClob()) {
            return jdbcInfo("text[]", Types.ARRAY, "text", Types.CLOB);
        } else {
            return jdbcInfo("varchar(%d)[]", type.length, Types.ARRAY, "varchar", Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("bool", Types.BIT);
    case ARRAY_BOOLEAN:
        return jdbcInfo("bool[]", Types.ARRAY, "bool", Types.BOOLEAN);
    case LONG:
        return jdbcInfo("int8", Types.BIGINT);
    case ARRAY_LONG:
        return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("float8", Types.DOUBLE);
    case ARRAY_DOUBLE:
        return jdbcInfo("float8[]", Types.ARRAY, "float8", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("timestamp", Types.TIMESTAMP);
    case ARRAY_TIMESTAMP:
        return jdbcInfo("timestamp[]", Types.ARRAY, "timestamp", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("varchar(40)", Types.VARCHAR);
    case ARRAY_BLOBID:
        return jdbcInfo("varchar(40)[]", Types.ARRAY, "varchar", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("varchar(36)", Types.VARCHAR);
        case UUID:
            return jdbcInfo("uuid", Types.OTHER);
        case SEQUENCE:
            return jdbcInfo("int8", Types.BIGINT);
        }
    case NODEARRAY:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("varchar(36)[]", Types.ARRAY, "varchar", Types.VARCHAR);
        case UUID:
            return jdbcInfo("uuid[]", Types.ARRAY, "uuid", Types.OTHER);
        case SEQUENCE:
            return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT);
        }
    case SYSNAME:
        return jdbcInfo("varchar(250)", Types.VARCHAR);
    case SYSNAMEARRAY:
        return jdbcInfo("varchar(250)[]", Types.ARRAY, "varchar", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("int2", Types.SMALLINT);
    case INTEGER:
        return jdbcInfo("int4", Types.INTEGER);
    case ARRAY_INTEGER:
        return jdbcInfo("int4[]", Types.ARRAY, "int4", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("serial", Types.INTEGER);
    case FTINDEXED:
        if (compatibilityFulltextTable) {
            return jdbcInfo("tsvector", Types.OTHER);
        } else {
            return jdbcInfo("text", Types.CLOB);
        }
    case FTSTORED:
        if (compatibilityFulltextTable) {
            return jdbcInfo("tsvector", Types.OTHER);
        } else {
            return jdbcInfo("text", Types.CLOB);
        }
    case CLUSTERNODE:
        return jdbcInfo("int4", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

From source file:org.apache.cayenne.migration.MigrationGenerator.java

protected String nameForJdbcType(int type) {
    switch (type) {
    case Types.ARRAY:
        return "array";
    case Types.BIGINT:
        return "bigInt";
    case Types.BINARY:
        return "binary";
    case Types.BIT:
        return "bit";
    case Types.BLOB:
        return "blob";
    case Types.BOOLEAN:
        return "boolean";
    case Types.CHAR:
        return "char";
    case Types.CLOB:
        return "clob";
    case Types.DATE:
        return "date";
    case Types.DECIMAL:
        return "decimal";
    case Types.DOUBLE:
        return "double";
    case Types.FLOAT:
        return "float";
    case Types.INTEGER:
        return "integer";
    case Types.LONGVARBINARY:
        return "longVarBinary";
    case Types.LONGVARCHAR:
        return "longVarChar";
    case Types.NUMERIC:
        return "numeric";
    case Types.REAL:
        return "real";
    case Types.SMALLINT:
        return "smallInt";
    case Types.TIME:
        return "time";
    case Types.TIMESTAMP:
        return "timestamp";
    case Types.TINYINT:
        return "tinyInt";
    case Types.VARBINARY:
        return "varBinary";
    case Types.VARCHAR:
        return "varchar";
    default:/*ww  w  . j  av  a  2s  .c o  m*/
        return null;
    }
}

From source file:org.executequery.gui.resultset.ResultSetTableModel.java

public void createTable(ResultSet resultSet) {

    if (!isOpenAndValid(resultSet)) {

        clearData();/*from  w w w .  j  a va  2s  .c  o  m*/
        return;
    }

    try {

        resetMetaData();
        ResultSetMetaData rsmd = resultSet.getMetaData();

        columnHeaders.clear();
        visibleColumnHeaders.clear();
        tableData.clear();

        int zeroBaseIndex = 0;
        int count = rsmd.getColumnCount();
        for (int i = 1; i <= count; i++) {

            zeroBaseIndex = i - 1;

            columnHeaders.add(new ResultSetColumnHeader(zeroBaseIndex, rsmd.getColumnLabel(i),
                    rsmd.getColumnName(i), rsmd.getColumnType(i), rsmd.getColumnTypeName(i)));
        }

        int recordCount = 0;
        interrupted = false;

        if (holdMetaData) {

            setMetaDataVectors(rsmd);
        }

        List<RecordDataItem> rowData;
        long time = System.currentTimeMillis();
        while (resultSet.next()) {

            if (interrupted || Thread.interrupted()) {

                throw new InterruptedException();
            }

            recordCount++;
            rowData = new ArrayList<RecordDataItem>(count);

            for (int i = 1; i <= count; i++) {

                zeroBaseIndex = i - 1;

                ResultSetColumnHeader header = columnHeaders.get(zeroBaseIndex);
                RecordDataItem value = recordDataItemFactory.create(header);

                try {

                    int dataType = header.getDataType();
                    switch (dataType) {

                    // some drivers (informix for example)
                    // was noticed to return the hashcode from
                    // getObject for -1 data types (eg. longvarchar).
                    // force string for these - others stick with
                    // getObject() for default value formatting

                    case Types.CHAR:
                    case Types.VARCHAR:
                        value.setValue(resultSet.getString(i));
                        break;
                    case Types.DATE:
                        value.setValue(resultSet.getDate(i));
                        break;
                    case Types.TIME:
                        value.setValue(resultSet.getTime(i));
                        break;
                    case Types.TIMESTAMP:
                        value.setValue(resultSet.getTimestamp(i));
                        break;
                    case Types.LONGVARCHAR:
                    case Types.CLOB:
                        value.setValue(resultSet.getClob(i));
                        break;
                    case Types.LONGVARBINARY:
                    case Types.VARBINARY:
                    case Types.BINARY:
                        value.setValue(resultSet.getBytes(i));
                        break;
                    case Types.BLOB:
                        value.setValue(resultSet.getBlob(i));
                        break;
                    case Types.BIT:
                    case Types.TINYINT:
                    case Types.SMALLINT:
                    case Types.INTEGER:
                    case Types.BIGINT:
                    case Types.FLOAT:
                    case Types.REAL:
                    case Types.DOUBLE:
                    case Types.NUMERIC:
                    case Types.DECIMAL:
                    case Types.NULL:
                    case Types.OTHER:
                    case Types.JAVA_OBJECT:
                    case Types.DISTINCT:
                    case Types.STRUCT:
                    case Types.ARRAY:
                    case Types.REF:
                    case Types.DATALINK:
                    case Types.BOOLEAN:
                    case Types.ROWID:
                    case Types.NCHAR:
                    case Types.NVARCHAR:
                    case Types.LONGNVARCHAR:
                    case Types.NCLOB:
                    case Types.SQLXML:

                        // use getObject for all other known types

                        value.setValue(resultSet.getObject(i));
                        break;

                    default:

                        // otherwise try as string

                        asStringOrObject(value, resultSet, i);
                        break;
                    }

                } catch (Exception e) {

                    try {

                        // ... and on dump, resort to string
                        value.setValue(resultSet.getString(i));

                    } catch (SQLException sqlException) {

                        // catch-all SQLException - yes, this is hideous

                        // noticed with invalid date formatted values in mysql

                        value.setValue("<Error - " + sqlException.getMessage() + ">");
                    }
                }

                if (resultSet.wasNull()) {

                    value.setNull();
                }

                rowData.add(value);
            }

            tableData.add(rowData);

            if (recordCount == maxRecords) {

                break;
            }

        }

        if (Log.isTraceEnabled()) {

            Log.trace("Finished populating table model - " + recordCount + " rows - [ "
                    + MiscUtils.formatDuration(System.currentTimeMillis() - time) + "]");
        }

        fireTableStructureChanged();

    } catch (SQLException e) {

        System.err.println("SQL error populating table model at: " + e.getMessage());
        Log.debug("Table model error - " + e.getMessage(), e);

    } catch (Exception e) {

        if (e instanceof InterruptedException) {

            Log.debug("ResultSet generation interrupted.", e);

        } else {

            String message = e.getMessage();
            if (StringUtils.isBlank(message)) {

                System.err.println("Exception populating table model.");

            } else {

                System.err.println("Exception populating table model at: " + message);
            }

            Log.debug("Table model error - ", e);
        }

    } finally {

        if (resultSet != null) {

            try {

                resultSet.close();

                Statement statement = resultSet.getStatement();
                if (statement != null) {

                    statement.close();
                }

            } catch (SQLException e) {
            }

        }
    }

}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        return getFromResultSetString(rs, index, column);
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        return getFromResultSetTimestamp(rs, index, column);
    case Types.ARRAY:
        Array array = rs.getArray(index);
        return array == null ? null : (Serializable) array.getArray();
    }/*from   w  w w  .ja  va 2  s .com*/
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        String string = rs.getString(index);
        if (column.getType() == ColumnType.BLOBID && string != null) {
            return column.getModel().getBinary(string);
        } else {//from   w w  w.  jav  a  2 s. c o  m
            return string;
        }
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        Timestamp ts = rs.getTimestamp(index);
        if (ts == null) {
            return null;
        } else {
            Serializable cal = new GregorianCalendar(); // XXX timezone
            ((Calendar) cal).setTimeInMillis(ts.getTime());
            return cal;
        }
    case Types.ARRAY:
        return (Serializable) rs.getArray(index).getArray();
    }
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

From source file:com.etcc.csc.dao.OraclePaymentDAO.java

public boolean veaAutoComments(long docId, String docType, String sessionId, String ipAddress, String userId,
        String veaName, OlcVpsInvoicesRecBean[] invoices) throws EtccException {

    try {/*from w  ww. j a  v  a2s .  c o m*/
        setConnection(Util.getDbConnection());
        cstmt = conn.prepareCall("{? = call OLCSC_VPS_COMMENTS.vea_auto_comments(?,?,?,?,?,?,?,?)}");

        Map typeMap = new HashMap();
        typeMap.put("TAG_OWNER.OLC_VPS_INVOICES_REC", OlcVpsInvoicesRec.class);
        typeMap.put("TAG_OWNER.OLC_ERROR_MSG_REC", ErrorMsgRec.class);
        conn.setTypeMap(typeMap);

        cstmt.registerOutParameter(1, Types.SMALLINT);
        cstmt.setLong(2, docId);
        cstmt.setString(3, docType);
        cstmt.setString(4, sessionId); //session id
        cstmt.setString(5, ipAddress);
        cstmt.setString(6, userId);
        cstmt.setString(7, veaName);

        ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_VPS_INVOICES_ARR", conn);
        ARRAY array = new ARRAY(arraydesc, conn, convertToOracleInvoices(invoices));
        cstmt.setArray(8, array);

        cstmt.registerOutParameter(9, Types.ARRAY, "TAG_OWNER.OLC_ERROR_MSG_ARR");

        cstmt.execute();

        byte success = cstmt.getByte(1);

        if (success == 0) {
            Collection errors = Util.convertErrorMsgs(cstmt.getArray(9));
            Iterator iter = errors.iterator();
            while (iter.hasNext()) {
                ErrorMessageDTO errorDTO = (ErrorMessageDTO) iter.next();
                logger.info("error occured in veaAutoComments:" + errorDTO.getMessage());
            }
            return false;
        }

        return true;

    } catch (SQLException ex) {
        throw new EtccException();
    } finally {
        closeConnection();
    }
}