Example usage for java.sql Types DATE

List of usage examples for java.sql Types DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

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

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Connection conn = DriverManager.getConnection("...", "username", "password");
    String query = "{CALL GETDATE(?,?)}";
    CallableStatement callableStatement = (CallableStatement) conn.prepareCall(query);

    callableStatement.setInt(1, 123);/*  ww w. ja v a  2s  .c om*/
    callableStatement.registerOutParameter(1, Types.DATE);
    callableStatement.executeQuery();

    Date date = callableStatement.getObject(2, Date.class);

}

From source file:Main.java

public static String getCloverTypeFromJdbcType(int jdbcDataType) {
    switch (jdbcDataType) {
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return "date";
    case Types.ARRAY:
    case Types.BINARY:
    case Types.DATALINK:
    case Types.BLOB:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.NULL:
    case Types.OTHER:
    case Types.REF:
    case Types.STRUCT:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        System.out.println("Outputting cbyte for Type: " + jdbcDataType);
        return "cbyte";
    case Types.BIT:
    case Types.BOOLEAN:
        return "boolean";
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
        return "numeric";
    case Types.INTEGER:
    case Types.SMALLINT:
        return "integer";
    case Types.BIGINT:
        return "long";
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.CLOB:
    case Types.LONGVARCHAR:
        return "string";
    }//from w w w .  j  a  v  a  2s  .  c  om
    System.out.println("Outputting string for unknown Type: " + jdbcDataType);
    return "string";
}

From source file:org.restsql.core.impl.SqlUtils.java

public static Object getObjectByColumnLabel(final ColumnMetaData column, final SqlRowSet resultSet) {
    Object value = null;/*from   www.jav  a  2 s.  c  om*/
    if (column.getColumnType() == Types.DATE && column.getColumnTypeName().equals("YEAR")) {
        value = new Integer(resultSet.getInt(column.getColumnLabel()));
        if (resultSet.wasNull()) {
            value = null;
        }
    } else {
        value = resultSet.getObject(column.getColumnLabel());
    }

    return value;
}

From source file:org.talend.dataquality.record.linkage.ui.composite.table.SortComparator.java

public static ISortComparator getSortComparator(int javaDataType) throws ParseException {
    switch (javaDataType) {
    case Types.DATE:
    case Types.TIME:
        return new SortComparator() {

            @Override//  w  ww  .  j  ava  2s  .c  o  m
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return java.sql.Date.valueOf(value1.toString())
                        .compareTo(java.sql.Date.valueOf(value2.toString()));
            }

        };
    case Types.TIMESTAMP:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Timestamp.valueOf(value1.toString()).compareTo(Timestamp.valueOf(value2.toString()));
            }

        };
    case Types.DOUBLE:
    case Types.REAL:
    case Types.FLOAT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Double.valueOf(value1.toString()).compareTo(Double.valueOf(value2.toString()));
            }

        };

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.NUMERIC:

        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Integer.valueOf(value1.toString()).compareTo(Integer.valueOf(value2.toString()));
            }

        };
    case Types.BIGINT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Long.valueOf(value1.toString()).compareTo(Long.valueOf(value2.toString()));
            }

        };
    case Types.DECIMAL:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                if (value1 instanceof BigDecimal) {
                    return ((BigDecimal) value1).compareTo((BigDecimal) value2);
                }
                BigDecimal b1 = new BigDecimal(value1.toString());
                BigDecimal b2 = new BigDecimal(value2.toString());
                return b1.compareTo(b2);
            }

        };
    case Types.BOOLEAN:
    case Types.BIT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Boolean.valueOf(value1.toString()).compareTo(Boolean.valueOf(value2.toString()));
            }

        };
    default:// String
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return value1.toString().compareTo(value2.toString());
            }

        };

    }

}

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:/* w w w . j a  va 2s .  com*/
        return null;
    }
}

From source file:org.talend.utils.sql.TalendTypeConvert.java

private static Map<String, Integer> getMap() {
    if (map == null) {
        map = new HashMap<String, Integer>();
        map.put(talendTypeName(Boolean.class), Types.BOOLEAN);
        map.put(talendTypeName(Byte.class), Types.DECIMAL);
        map.put(talendTypeName(Character.class), Types.CHAR);
        map.put(talendTypeName(Date.class), Types.DATE);
        map.put(talendTypeName(String.class), Types.CLOB);
        map.put(talendTypeName(Double.class), Types.DOUBLE);
        map.put(talendTypeName(Float.class), Types.FLOAT);
        map.put(talendTypeName(Integer.class), Types.INTEGER);
        map.put(talendTypeName(Long.class), Types.INTEGER);
        map.put(talendTypeName(Short.class), Types.SMALLINT);
    }//w  w  w.  j  a  v  a  2 s .c o m
    return map;
}

From source file:org.restsql.core.impl.SqlUtils.java

public static Object getObjectByColumnNumber(final ColumnMetaData column, final SqlRowSet resultSet) {
    Object value = null;/*from   w  ww .  jav  a2  s .  c  om*/
    if (column.getColumnType() == Types.DATE && column.getColumnTypeName().equals("YEAR")) {
        value = new Integer(resultSet.getInt(column.getColumnNumber()));
        if (resultSet.wasNull()) {
            value = null;
        }
    } else {
        value = resultSet.getObject(column.getColumnNumber());
    }
    return value;
}

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?// w  ww.ja v a 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  www  .  ja  va  2 s  .  com*/
 */
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:Main.java

/**
 * Gets the name of the type to be used with the internal dbms
 * /*from   ww  w .  ja  va  2  s .com*/
 * @param type
 *            java.sql.Types constant
 * 
 * @return String
 * 
 * @throws RuntimeException
 *             If the Type is not recognized
 */
public static String getTypeString(int type) {
    switch (type) {
    case Types.BIGINT:
        return "BIGINT";

    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "VARCHAR";

    case Types.DATE:
        return "DATE";

    case Types.DECIMAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";

    case Types.INTEGER:
        return "INTEGER";

    case Types.SMALLINT:
        return "SHORT";

    case Types.TINYINT:
        return "BYTE";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "BINARY";

    case Types.TIMESTAMP:
        return "TIMESTAMP";

    case Types.TIME:
        return "TIME";

    default:
        throw new RuntimeException("Cannot edit the type: " + type);
    }
}