Example usage for java.sql Types NCHAR

List of usage examples for java.sql Types NCHAR

Introduction

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

Prototype

int NCHAR

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

Click Source Link

Document

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

Usage

From source file:org.apache.hadoop.hive.ql.dataImport.HiveTypes.java

public static String toHiveType(int sqlType) {

    switch (sqlType) {
    case Types.INTEGER:
    case Types.SMALLINT:
        return "INT";
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
    case Types.OTHER:
        return "STRING";
    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";
    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.TINYINT:
        return "TINYINT";
    case Types.BIGINT:
        return "BIGINT";
    default:/*from   w  ww  .j a  v a2s.  co  m*/
        return null;
    }
}

From source file:org.apache.sqoop.hive.HiveTypes.java

/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?//from   w ww  .  java 2 s . c  om
 */
public static String toHiveType(int sqlType) {

    switch (sqlType) {
    case Types.INTEGER:
    case Types.SMALLINT:
        return "INT";
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
        return "STRING";
    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";
    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.TINYINT:
        return "TINYINT";
    case Types.BIGINT:
        return "BIGINT";
    default:
        // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
        // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return null;
    }
}

From source file:org.apache.sqoop.hive.HiveTypesORC.java

/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?//from  w ww.j a v a  2  s  . co m
 */
public static String toHiveType(int sqlType) {

    switch (sqlType) {
    case Types.INTEGER:
    case Types.SMALLINT:
        return "INT";
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
        return "STRING";
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";
    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.TINYINT:
        return "TINYINT";
    case Types.BIGINT:
        return "BIGINT";
    case Types.DECIMAL:
        return "DECIMAL";
    default:
        // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
        // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return null;
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.TypeMapper.java

private static Class mapSQLType(final int t) {
    switch (t) {/*from  w ww.  jav a  2s .  c  o m*/
    case Types.ARRAY:
        return Object[].class;
    case Types.BIGINT:
        return Long.class;
    case Types.BINARY:
        return byteArrayClass;
    case Types.BIT:
        return Boolean.class;
    case Types.BLOB:
        return Blob.class;
    case Types.BOOLEAN: // Types.BOOLEAN was not part of JDK1.2.2
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.CLOB:
        return Clob.class;
    case Types.DATALINK: // Types.DATALINK was not part of JDK 1.2.2
        return URL.class;
    case Types.DATE:
        return java.sql.Date.class;
    case Types.DECIMAL:
        return java.math.BigDecimal.class;
    case Types.DISTINCT:
        return Object.class;
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.JAVA_OBJECT:
        return Object.class;
    case Types.LONGVARBINARY:
        return byteArrayClass;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NCLOB:
        return NClob.class;
    case Types.NULL:
        return Object.class;
    case Types.NUMERIC:
        return java.math.BigDecimal.class;
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
        return String.class;
    case Types.OTHER:
        return Object.class;
    case Types.REAL:
        return Float.class;
    case Types.REF:
        return Ref.class;
    case Types.ROWID:
        return RowId.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.STRUCT:
        return Struct.class;
    case Types.SQLXML:
        return SQLXML.class;
    case Types.TIME:
        return Time.class;
    case Types.TIMESTAMP:
        return Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARBINARY:
        return byteArrayClass;
    case Types.VARCHAR:
        return String.class;
    default:
        return Object.class;
    }
}

From source file:at.molindo.dbcopy.util.Utils.java

public static boolean isStringType(int dataType) {
    switch (dataType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
        return true;
    default:/* ww  w  .  j av a2 s. c  om*/
        return false;
    }
}

From source file:com.redsqirl.workflow.utils.jdbc.GenericConfFile.java

public GenericConfFile(String name, Connection conn) throws SQLException {
    dictionaryName = name;/*from w w w  .ja v  a 2  s . c  om*/

    databaseMetaData = conn.getMetaData();

    typeRecognized = new LinkedHashMap<Integer, FieldType>();
    typeRecognized.put(Types.BOOLEAN, FieldType.BOOLEAN);
    typeRecognized.put(Types.DATE, FieldType.DATETIME);
    typeRecognized.put(Types.TIME, FieldType.DATETIME);
    typeRecognized.put(Types.DOUBLE, FieldType.DOUBLE);
    typeRecognized.put(Types.NUMERIC, FieldType.DOUBLE);
    typeRecognized.put(Types.DECIMAL, FieldType.DOUBLE);
    typeRecognized.put(Types.REAL, FieldType.DOUBLE);
    typeRecognized.put(Types.FLOAT, FieldType.FLOAT);
    typeRecognized.put(Types.INTEGER, FieldType.INT);
    typeRecognized.put(Types.SMALLINT, FieldType.INT);
    typeRecognized.put(Types.TINYINT, FieldType.INT);
    typeRecognized.put(Types.BIGINT, FieldType.LONG);
    typeRecognized.put(Types.VARCHAR, FieldType.STRING);
    typeRecognized.put(Types.CHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NCHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGNVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.TIMESTAMP, FieldType.TIMESTAMP);

}

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

protected ARRAY createArray(Connection con, Object value, String typeName) throws SQLException {

    if (value == null)
        return null;

    ArrayDescriptor arrayStructDesc = safeCreateArrayDescriptor(typeName, con);

    if (value == null)
        return null;

    if (value.getClass().isArray()) {
        value = Arrays.asList((Object[]) value);
    }//from   ww w.  j  a  va  2s . co m

    List records = (List) value;
    String baseName = arrayStructDesc.getBaseName();
    int baseType = arrayStructDesc.getBaseType();
    if (baseType == Types.VARCHAR || baseType == Types.CHAR || baseType == Types.CLOB
            || baseType == Types.NUMERIC || baseType == Types.INTEGER || baseType == Types.BIGINT
            || baseType == Types.FLOAT || baseType == Types.DOUBLE || baseType == Types.DECIMAL
            || baseType == Types.NCHAR || baseType == Types.NVARCHAR || baseType == Types.NCLOB) {
        return new ARRAY(arrayStructDesc, con, records.toArray()); // primitive array
    } else {

        Object[] structArray = new Object[records.size()];

        for (int i = 0; i < structArray.length; i++) {
            Object record = records.get(i);

            if (baseType == OracleTypes.JAVA_STRUCT || baseType == OracleTypes.JAVA_OBJECT
                    || baseType == OracleTypes.STRUCT || baseType == OracleTypes.JAVA_STRUCT) {
                record = createStruct(con, record, baseName);
            } else if (baseType == OracleTypes.ARRAY) {
                record = createArray(con, record, baseName);
            }
            structArray[i] = record;
        }

        return new ARRAY(arrayStructDesc, con, structArray);
    }
}

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

/**
 * Resolve a database-specific type to the Java type that should contain it.
 * @param sqlType     sql type/*  w  ww  .  jav a2  s  .  c o m*/
 * @return the name of a Java type to hold the sql datatype, or null if none.
 */
public String toJavaType(int sqlType) {
    // Mappings taken from:
    // http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
    if (sqlType == Types.INTEGER) {
        return "Integer";
    } else if (sqlType == Types.VARCHAR) {
        return "String";
    } else if (sqlType == Types.CHAR) {
        return "String";
    } else if (sqlType == Types.LONGVARCHAR) {
        return "String";
    } else if (sqlType == Types.NVARCHAR) {
        return "String";
    } else if (sqlType == Types.NCHAR) {
        return "String";
    } else if (sqlType == Types.LONGNVARCHAR) {
        return "String";
    } else if (sqlType == Types.NUMERIC) {
        return "java.math.BigDecimal";
    } else if (sqlType == Types.DECIMAL) {
        return "java.math.BigDecimal";
    } else if (sqlType == Types.BIT) {
        return "Boolean";
    } else if (sqlType == Types.BOOLEAN) {
        return "Boolean";
    } else if (sqlType == Types.TINYINT) {
        return "Integer";
    } else if (sqlType == Types.SMALLINT) {
        return "Integer";
    } else if (sqlType == Types.BIGINT) {
        return "Long";
    } else if (sqlType == Types.REAL) {
        return "Float";
    } else if (sqlType == Types.FLOAT) {
        return "Double";
    } else if (sqlType == Types.DOUBLE) {
        return "Double";
    } else if (sqlType == Types.DATE) {
        return "java.sql.Date";
    } else if (sqlType == Types.TIME) {
        return "java.sql.Time";
    } else if (sqlType == Types.TIMESTAMP) {
        return "java.sql.Timestamp";
    } else if (sqlType == Types.BINARY || sqlType == Types.VARBINARY) {
        return BytesWritable.class.getName();
    } else if (sqlType == Types.CLOB) {
        return ClobRef.class.getName();
    } else if (sqlType == Types.BLOB || sqlType == Types.LONGVARBINARY) {
        return BlobRef.class.getName();
    } else {
        // TODO(aaron): Support DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT.
        // Return null indicating database-specific manager should return a
        // java data type if it can find one for any nonstandard type.
        return null;
    }
}

From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.// w  w  w .ja  va2s  . c  o m
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:org.apache.tajo.storage.jdbc.JdbcMetadataProviderBase.java

private TypeDesc convertDataType(ResultSet res) throws SQLException {
    final int typeId = res.getInt("DATA_TYPE");

    switch (typeId) {
    case Types.BOOLEAN:
        return new TypeDesc(newSimpleDataType(Type.BOOLEAN));

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return new TypeDesc(newSimpleDataType(Type.INT4));

    case Types.DISTINCT: // sequence for postgresql
    case Types.BIGINT:
        return new TypeDesc(newSimpleDataType(Type.INT8));

    case Types.FLOAT:
        return new TypeDesc(newSimpleDataType(Type.FLOAT4));

    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DOUBLE:
        return new TypeDesc(newSimpleDataType(Type.FLOAT8));

    case Types.DATE:
        return new TypeDesc(newSimpleDataType(Type.DATE));

    case Types.TIME:
        return new TypeDesc(newSimpleDataType(Type.TIME));

    case Types.TIMESTAMP:
        return new TypeDesc(newSimpleDataType(Type.TIMESTAMP));

    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return new TypeDesc(newSimpleDataType(Type.TEXT));

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return new TypeDesc(newSimpleDataType(Type.BLOB));

    default:/*  w ww.  j  a va2  s.  c  o  m*/
        throw SQLExceptionUtil.toSQLException(new UnsupportedDataTypeException(typeId + ""));
    }
}