Example usage for java.sql Types LONGVARCHAR

List of usage examples for java.sql Types LONGVARCHAR

Introduction

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

Prototype

int LONGVARCHAR

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

Click Source Link

Document

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

Usage

From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java

private static Class<?> getJavaType(int sqltype, int precision, int scale) {
    switch (sqltype) {
    case Types.BIGINT:
        return Long.class;
    case Types.BIT:
        return Boolean.class;
    case Types.BOOLEAN:
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.DECIMAL:
        return getNumericType(precision, scale);
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NUMERIC:
        return getNumericType(precision, scale);
    case Types.REAL:
        return Float.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.DATE:
        return java.sql.Timestamp.class;
    case Types.TIME:
        return java.sql.Time.class;
    case Types.TIMESTAMP:
        return java.sql.Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARCHAR:
        return String.class;
    case Types.BLOB:
        return byte[].class;
    case Types.LONGVARBINARY:
        return byte[].class;
    case Types.CLOB:
        return String.class;
    case Types.BINARY:
        return byte[].class;
    case Types.VARBINARY:
        return byte[].class;
    case Types.NVARCHAR:
        return String.class;
    case Types.NCHAR:
        return String.class;
    case Types.LONGNVARCHAR:
        return String.class;
    case -155://from   w w  w  .  j  a va 2s  . c  om
        return java.sql.Timestamp.class;
    default:
        return Object.class;
    }
}

From source file:org.jumpmind.db.platform.AbstractJdbcDdlReader.java

public AbstractJdbcDdlReader(IDatabasePlatform platform) {
    this.platform = platform;

    _defaultSizes.put(new Integer(Types.CHAR), "254");
    _defaultSizes.put(new Integer(Types.VARCHAR), "254");
    _defaultSizes.put(new Integer(Types.LONGVARCHAR), "254");
    _defaultSizes.put(new Integer(Types.BINARY), "254");
    _defaultSizes.put(new Integer(Types.VARBINARY), "254");
    _defaultSizes.put(new Integer(Types.LONGVARBINARY), "254");
    _defaultSizes.put(new Integer(Types.INTEGER), "32");
    _defaultSizes.put(new Integer(Types.BIGINT), "64");
    _defaultSizes.put(new Integer(Types.REAL), "7,0");
    _defaultSizes.put(new Integer(Types.FLOAT), "15,0");
    _defaultSizes.put(new Integer(Types.DOUBLE), "15,0");
    _defaultSizes.put(new Integer(Types.DECIMAL), "15,15");
    _defaultSizes.put(new Integer(Types.NUMERIC), "15,15");

    _columnsForTable = initColumnsForTable();
    _columnsForColumn = initColumnsForColumn();
    _columnsForPK = initColumnsForPK();//from  www  .j  a va 2  s  .  com
    _columnsForFK = initColumnsForFK();
    _columnsForIndex = initColumnsForIndex();

    initWildcardString(platform);
}

From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java

public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException {
    String value = "";

    switch (colType) {
    case Types.BIT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }//from w w w .  jav a 2 s . c o m
        break;
    case Types.BOOLEAN:
        if (jdbcObject != null) {
            value = new Boolean(jdbcObject.toString()).toString();
        }
        break;
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
    case Types.NUMERIC:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.CLOB:
        if (jdbcObject != null) {
            try {
                value = read((Clob) jdbcObject);
            } catch (SQLException sqle) {
                value = "";
            } catch (IOException ioe) {
                value = "";
            }
        }
        break;
    case Types.ARRAY:
        try {
            ResultSet rs = ((Array) jdbcObject).getResultSet();
            int arrayType = ((Array) jdbcObject).getBaseType();
            boolean isNotNew = false;
            while (rs.next()) {
                String current = formatJDBCObject(rs.getObject(2), arrayType);
                if ("".equals(current.trim()) == false) {
                    if (isNotNew) {
                        value = value + ",";
                    } else {
                        isNotNew = !isNotNew;
                    }
                    value = value + current;
                }
            }
            if ("".equals(value) == false) {
                value = "{" + value + "}";
            }
        } catch (SQLException sqle) {
            value = "";
        }
        break;
    case Types.JAVA_OBJECT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }
        break;
    case Types.DATE:
        if (jdbcObject != null) {
            value = formatter.formatDate(jdbcObject);
        }
        break;
    case Types.TIME:
        if (jdbcObject != null) {
            value = ((Time) jdbcObject).toString();
        }
        break;
    case Types.TIMESTAMP:
        if (jdbcObject != null) {
            value = formatter.formatTimestamp(jdbcObject);
        }
        break;
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        if (jdbcObject != null) {
            value = jdbcObject.toString();
        } else {
            value = "NULL";
        }
        break;
    case Types.BINARY:
        value = new String((byte[]) jdbcObject);
        break;
    default:
        value = "";
    }
    if (value == null) {
        value = "";
    }
    return value;
}

From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java

public static String encoding(String source, int sqlType, String sourceEncoding, String targetEncoding) {
    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
        if (false == StringUtils.isEmpty(source)) {
            String fromEncoding = StringUtils.isBlank(sourceEncoding) ? "UTF-8" : sourceEncoding;
            String toEncoding = StringUtils.isBlank(targetEncoding) ? "UTF-8" : targetEncoding;

            // if (false == StringUtils.equalsIgnoreCase(fromEncoding,
            // toEncoding)) {
            try {
                return new String(source.getBytes(fromEncoding), toEncoding);
            } catch (UnsupportedEncodingException e) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }/*  w ww . j  a v a2  s . c  o  m*/
            // }
        }
    }

    return source;
}

From source file:org.apache.openjpa.jdbc.schema.Schemas.java

/**
 * Return the java type for the given SQL type from {@link Types}.
 *//* www .  ja va 2s  .  co m*/
public static Class<?> getJavaType(int type, int size, int decimals) {
    switch (type) {
    case Types.CHAR:
        if (size == 1)
            return char.class;
        // no break
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return String.class;
    case Types.BIT:
        return boolean.class;
    case Types.TINYINT:
        return byte.class;
    case Types.SMALLINT:
        return short.class;
    case Types.INTEGER:
        return int.class;
    case Types.BIGINT:
        return long.class;
    case Types.REAL:
    case Types.FLOAT:
        return float.class;
    case Types.DOUBLE:
    case Types.NUMERIC:
        return double.class;
    case Types.DECIMAL:
        // oracle uses this for everything, so look at size and decimals
        if (decimals == 0 && size < 10)
            return int.class;
        else if (decimals == 0)
            return long.class;
        return double.class;
    // ### return a BigDecimal if the size if out of double range?
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return Date.class;
    default:
        return Object.class;
    }
}

From source file:org.sakaiproject.mailarchive.impl.conversion.ExtractXMLToColumns.java

public Object getValidateSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    byte[] rv = null;
    switch (metadata.getColumnType(1)) {
    case Types.BLOB:
        Blob blob = rs.getBlob(1);
        if (blob != null) {
            rv = blob.getBytes(1L, (int) blob.length());
        } else {/* w w  w  .j  ava  2 s  . co  m*/
            System.out.println("getValidateSource(" + id + ") blob ==  null");
        }
        break;
    case Types.CLOB:
        Clob clob = rs.getClob(1);
        if (clob != null) {
            rv = clob.getSubString(1L, (int) clob.length()).getBytes();
        }
        break;
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        rv = rs.getString(1).getBytes();
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        rv = rs.getBytes(1);
        break;
    }
    // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n");
    return rv;
}

From source file:org.fao.geonet.arcgis.ArcSDEJdbcConnection.java

@Override
public Map<String, String> retrieveMetadata(AtomicBoolean cancelMonitor, String arcSDEVersion)
        throws Exception {
    Map<String, String> results = new HashMap<>();

    ArcSDEVersionFactory arcSDEVersionFactory = new ArcSDEVersionFactory();
    String metadataTable = arcSDEVersionFactory.getTableName(arcSDEVersion);
    String columnName = arcSDEVersionFactory.getMetadataColumnName(arcSDEVersion);

    String sqlQuery = "SELECT " + columnName + ", UUID FROM " + metadataTable;

    getJdbcTemplate().query(sqlQuery, new RowCallbackHandler() {
        @Override/*www.j  a v a 2  s .c  o m*/
        public void processRow(ResultSet rs) throws SQLException {
            // Cancel processing
            if (cancelMonitor.get()) {
                Log.warning(ARCSDE_LOG_MODULE_NAME,
                        "Cancelling metadata retrieve using " + "ArcSDE connection (via JDBC)");
                rs.getStatement().cancel();
                results.clear();
            }

            String document = "";
            int colId = rs.findColumn(columnName);
            int colIdUuid = rs.findColumn("UUID");
            // very simple type check:
            if (rs.getObject(colId) != null) {
                if (rs.getMetaData().getColumnType(colId) == Types.BLOB) {
                    Blob blob = rs.getBlob(columnName);
                    byte[] bdata = blob.getBytes(1, (int) blob.length());
                    document = new String(bdata);

                } else if (rs.getMetaData().getColumnType(colId) == Types.LONGVARBINARY) {
                    byte[] byteData = rs.getBytes(colId);
                    document = new String(byteData);

                } else if (rs.getMetaData().getColumnType(colId) == Types.LONGNVARCHAR
                        || rs.getMetaData().getColumnType(colId) == Types.LONGVARCHAR
                        || rs.getMetaData().getColumnType(colId) == Types.VARCHAR
                        || rs.getMetaData().getColumnType(colId) == Types.SQLXML) {
                    document = rs.getString(colId);

                } else {
                    throw new SQLException("Trying to harvest from a column with an invalid datatype: "
                            + rs.getMetaData().getColumnTypeName(colId));
                }

                String uuid = rs.getString(colIdUuid);
                ;
                results.put(uuid, document);
            }

        }
    });

    Log.info(ARCSDE_LOG_MODULE_NAME,
            "Finished retrieving metadata, found: #" + results.size() + " metadata records");

    return results;
}

From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobCollectionConversionHandler.java

public Object getValidateSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    byte[] rv = null;
    switch (metadata.getColumnType(1)) {
    case Types.BLOB:
        Blob blob = rs.getBlob(1);
        if (blob != null) {
            //System.out.println("getValidateSource(" + id + ") blob == " + blob + " blob.length == " + blob.length());
            rv = blob.getBytes(1L, (int) blob.length());
        } else {// ww  w .j av  a 2s .  co m
            System.out.println("getValidateSource(" + id + ") blob is null");
        }
        break;
    case Types.CLOB:
        Clob clob = rs.getClob(1);
        if (clob != null) {
            rv = clob.getSubString(1L, (int) clob.length()).getBytes();
        }
        break;
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        rv = rs.getString(1).getBytes();
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        rv = rs.getBytes(1);
        break;
    }
    //System.out.println("getValidateSource(" + id + ") \n" + rv + "\n");
    return rv;
}

From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobResourcesConversionHandler.java

public Object getValidateSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    byte[] rv = null;
    switch (metadata.getColumnType(1)) {
    case Types.BLOB:
        Blob blob = rs.getBlob(1);
        if (blob != null) {
            //System.out.println("getValidateSource(" + id + ") blob == " + blob + " blob.length == " + blob.length());
            rv = blob.getBytes(1L, (int) blob.length());
        } else {//from  w  w w .  j a va 2s  .  c o m
            System.out.println("getValidateSource(" + id + ") blob is null");
        }
        break;
    case Types.CLOB:
        Clob clob = rs.getClob(1);
        if (clob != null) {
            rv = clob.getSubString(1L, (int) clob.length()).getBytes();
        }
        break;
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        rv = rs.getString(1).getBytes();
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        rv = rs.getBytes(1);
        break;
    }
    // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n");
    return rv;

    //return rs.getBytes(1);
}

From source file:org.apache.sqoop.manager.ConnManager.java

/**
 * Resolve a database-specific type to Avro data type.
 * @param sqlType     sql type// w ww .  ja  v a2 s.  c  o m
 * @return            avro type
 */
public Type toAvroType(int sqlType) {
    switch (sqlType) {
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return Type.INT;
    case Types.BIGINT:
        return Type.LONG;
    case Types.BIT:
    case Types.BOOLEAN:
        return Type.BOOLEAN;
    case Types.REAL:
        return Type.FLOAT;
    case Types.FLOAT:
    case Types.DOUBLE:
        return Type.DOUBLE;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return Type.STRING;
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        return Type.STRING;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return Type.STRING;
    case Types.BLOB:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return Type.BYTES;
    default:
        throw new IllegalArgumentException("Cannot convert SQL type " + sqlType);
    }
}