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:com.nabla.wapp.server.json.SqlColumn.java

public SqlColumn(String label, int type, int length) {
    this.label = label;
    this.type = (type == Types.TINYINT) ? (length == 1 ? Types.BOOLEAN : type) : type;
    if (log.isDebugEnabled()) {
        String s;/*from  ww  w  . j  av  a  2s.  c om*/
        switch (this.type) {
        case Types.BIGINT:
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
            s = "INTEGER";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            s = "BOOLEAN";
            break;
        case Types.DATE:
            s = "DATE";
            break;
        case Types.TIMESTAMP:
            s = "TIMESTAMP";
            break;
        case Types.DOUBLE:
            s = "DOUBLE";
            break;
        case Types.FLOAT:
            s = "FLOAT";
            break;
        case Types.NULL:
            s = "NULL";
            break;
        default:
            s = "STRING";
            break;
        }
        log.debug("column '" + this.label + "' " + s);
    }
}

From source file:org.apache.ojb.broker.metadata.FieldTypeClasses.java

/**
 * Returns a {@link FieldType} instance for the given sql type
 * (see {@link java.sql.Types}) as specified in JDBC 3.0 specification
 * (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion Tables</em>).
 *
 * @param jdbcType Specify the type to look for.
 * @return A new specific {@link FieldType} instance.
 *///from w  ww .ja v a2s  . c o m
static FieldType newFieldType(JdbcType jdbcType) {
    FieldType result = null;
    switch (jdbcType.getType()) {
    case Types.ARRAY:
        result = new ArrayFieldType();
        break;
    case Types.BIGINT:
        result = new LongFieldType();
        break;
    case Types.BINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.BIT:
        result = new BooleanFieldType();
        break;
    case Types.BLOB:
        result = new BlobFieldType();
        break;
    case Types.CHAR:
        result = new StringFieldType();
        break;
    case Types.CLOB:
        result = new ClobFieldType();
        break;
    case Types.DATE:
        result = new DateFieldType();
        break;
    case Types.DECIMAL:
        result = new BigDecimalFieldType();
        break;
    // Not needed, user have to use the underlying sql datatype in OJB mapping files
    //            case Types.DISTINCT:
    //                result = new DistinctFieldType();
    //                break;
    case Types.DOUBLE:
        result = new DoubleFieldType();
        break;
    case Types.FLOAT:
        result = new FloatFieldType();
        break;
    case Types.INTEGER:
        result = new IntegerFieldType();
        break;
    case Types.JAVA_OBJECT:
        result = new JavaObjectFieldType();
        break;
    case Types.LONGVARBINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.LONGVARCHAR:
        result = new StringFieldType();
        break;
    case Types.NUMERIC:
        result = new BigDecimalFieldType();
        break;
    case Types.REAL:
        result = new FloatFieldType();
        break;
    case Types.REF:
        result = new RefFieldType();
        break;
    case Types.SMALLINT:
        result = new ShortFieldType();
        break;
    case Types.STRUCT:
        result = new StructFieldType();
        break;
    case Types.TIME:
        result = new TimeFieldType();
        break;
    case Types.TIMESTAMP:
        result = new TimestampFieldType();
        break;
    case Types.TINYINT:
        result = new ByteFieldType();
        break;
    case Types.VARBINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.VARCHAR:
        result = new StringFieldType();
        break;
    case Types.OTHER:
        result = new JavaObjectFieldType();
        break;
    //
    //            case Types.NULL:
    //                result = new NullFieldType();
    //                break;

    //#ifdef JDBC30
    case Types.BOOLEAN:
        result = new BooleanFieldType();
        break;
    case Types.DATALINK:
        result = new URLFieldType();
        break;
    //#endif
    default:
        throw new OJBRuntimeException("Unkown or not supported field type specified, specified jdbc type was '"
                + jdbcType + "', as string: " + JdbcTypesHelper.getSqlTypeAsString(jdbcType.getType()));
    }
    // make sure that the sql type was set
    result.setSqlType(jdbcType);
    return result;
}

From source file:com.streamsets.pipeline.stage.it.AllNullTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, null), true, Types.BOOLEAN },
            { Field.create(Field.Type.CHAR, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE, null), false, 0 },
            { Field.create(Field.Type.SHORT, null), true, Types.INTEGER },
            { Field.create(Field.Type.INTEGER, null), true, Types.INTEGER },
            { Field.create(Field.Type.LONG, null), true, Types.BIGINT },
            { Field.create(Field.Type.FLOAT, null), true, Types.FLOAT },
            { Field.create(Field.Type.DOUBLE, null), true, Types.DOUBLE },
            { Field.create(Field.Type.DATE, null), true, Types.DATE },
            { Field.create(Field.Type.DATETIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.TIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.DECIMAL, null), true, Types.DECIMAL },
            { Field.create(Field.Type.STRING, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE_ARRAY, null), true, Types.BINARY },
            { Field.create(Field.Type.MAP, null), false, 0 }, { Field.create(Field.Type.LIST, null), false, 0 },
            { Field.create(Field.Type.LIST_MAP, null), false, 0 }, });
}

From source file:org.apache.ddlutils.platform.DefaultValueHelper.java

/**
 * Converts the given default value from the specified original to the target
 * jdbc type./*from  w w w  . j  a v a 2s  . com*/
 * 
 * @param defaultValue     The default value
 * @param originalTypeCode The original type code
 * @param targetTypeCode   The target type code
 * @return The converted default value 
 */
public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) {
    String result = defaultValue;

    if (defaultValue != null) {
        switch (originalTypeCode) {
        case Types.BIT:
        case Types.BOOLEAN:
            result = convertBoolean(defaultValue, targetTypeCode).toString();
            break;
        case Types.DATE:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Date date = Date.valueOf(result);

                    return new Timestamp(date.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        case Types.TIME:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Time time = Time.valueOf(result);

                    return new Timestamp(time.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        }
    }
    return result;
}

From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java

public void testMapping() {
    Map<Integer, Class> testData = new HashMap<Integer, Class>();
    testData.put(Types.CHAR, String.class);
    testData.put(Types.VARCHAR, String.class);
    testData.put(Types.LONGVARCHAR, String.class);
    testData.put(Types.NUMERIC, BigDecimal.class);
    testData.put(Types.DECIMAL, BigDecimal.class);
    testData.put(Types.BIT, Boolean.class);
    testData.put(Types.BOOLEAN, Boolean.class);
    testData.put(Types.TINYINT, Byte.class);
    testData.put(Types.SMALLINT, Short.class);
    testData.put(Types.INTEGER, Integer.class);
    testData.put(Types.BIGINT, Long.class);
    testData.put(Types.REAL, Float.class);
    testData.put(Types.FLOAT, Double.class);
    testData.put(Types.DOUBLE, Double.class);
    testData.put(Types.BINARY, byte[].class);
    testData.put(Types.VARBINARY, byte[].class);
    testData.put(Types.LONGVARBINARY, byte[].class);
    testData.put(Types.DATE, java.sql.Date.class);
    testData.put(Types.TIMESTAMP, java.sql.Timestamp.class);
    testData.put(Types.TIME, java.sql.Time.class);
    testData.put(Types.CLOB, java.sql.Clob.class);
    testData.put(Types.BLOB, java.sql.Blob.class);
    testData.put(Types.ARRAY, java.sql.Array.class);
    testData.put(Types.STRUCT, java.sql.Struct.class);
    testData.put(Types.REF, java.sql.Ref.class);
    testData.put(Types.DATALINK, java.net.URL.class);

    for (int type : testData.keySet()) {
        Class result = SQLTypeMapUtil.sqlTypeToClass(type, null);
        log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName());
        assertEquals(testData.get(type), result);
    }/*from  w w  w  .ja va  2  s.c om*/

    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String"));
    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String"));
}

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

/**
 * Return the SQL type name for the given {@link Types} constant.
 *///w  ww . j ava2 s. c  om
public static String getJDBCName(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.CHAR:
        return "char";
    case Types.CLOB:
        return "clob";
    case Types.DATE:
        return "date";
    case Types.DECIMAL:
        return "decimal";
    case Types.DISTINCT:
        return "distinct";
    case Types.DOUBLE:
        return "double";
    case Types.FLOAT:
        return "float";
    case Types.INTEGER:
        return "integer";
    case Types.JAVA_OBJECT:
        return "java_object";
    case Types.LONGVARBINARY:
        return "longvarbinary";
    case Types.LONGVARCHAR:
        return "longvarchar";
    case Types.NULL:
        return "null";
    case Types.NUMERIC:
        return "numeric";
    case Types.OTHER:
        return "other";
    case Types.REAL:
        return "real";
    case Types.REF:
        return "ref";
    case Types.SMALLINT:
        return "smallint";
    case Types.STRUCT:
        return "struct";
    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:
        return "unknown(" + type + ")";
    }
}

From source file:com.swiftcorp.portal.report.dao.MPRStoredProcedure.java

public MPRStoredProcedure(DataSource ds) {
    super(ds, STORED_PROC_NAME);

    //Return Resultset parameters
    declareParameter(new SqlReturnResultSet("rs", new RowCallbackHandlerImpl()));

    //input parameters
    declareParameter(new SqlParameter("FROM_DATE", Types.DATE));
    declareParameter(new SqlParameter("TO_DATE", Types.DATE));
    System.out.println(" MPRStoredProcedure ");

    try {/*from  ww w.  jav  a 2 s  . c o m*/
        compile();
    } catch (Throwable t) {
        t.printStackTrace();
    }

    System.out.println(" MPRStoredProcedure compile ");
}

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

public GenericConfFile(String name, Connection conn) throws SQLException {
    dictionaryName = name;//  w w  w  . j  ava  2s . c  o m

    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:org.georepublic.db.utils.ResultSetConverter.java

public static JSONArray convert(ResultSet rs) throws SQLException, JSONException {

    JSONArray json = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();

    while (rs.next()) {
        int numColumns = rsmd.getColumnCount();
        JSONObject obj = new JSONObject();

        for (int i = 1; i < numColumns + 1; i++) {
            String column_name = rsmd.getColumnName(i);

            if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                obj.put(column_name, rs.getArray(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                obj.put(column_name, rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                obj.put(column_name, rs.getBoolean(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                obj.put(column_name, rs.getBlob(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                obj.put(column_name, rs.getDouble(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                obj.put(column_name, rs.getFloat(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                obj.put(column_name, rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                obj.put(column_name, rs.getNString(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                obj.put(column_name, rs.getString(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                obj.put(column_name, rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                obj.put(column_name, rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                obj.put(column_name, rs.getDate(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                obj.put(column_name, rs.getTimestamp(column_name));
            } else {
                obj.put(column_name, rs.getObject(column_name));
            }/*from  ww w . j av  a2  s.co m*/
        }

        json.put(obj);
    }

    return json;

}

From source file:co.nubetech.hiho.mapreduce.lib.db.apache.OracleDataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 *//* w w w .j a  v a 2s .c o  m*/
@Override
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new OracleDateSplitter();

    default:
        return super.getSplitter(sqlDataType);
    }
}