List of usage examples for java.sql Types DATE
int DATE
To view the source code for java.sql Types DATE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE
.
From source file:com.cloudera.sqoop.hive.HiveTypes.java
/** * @return true if a sql type can't be translated to a precise match * in Hive, and we have to cast it to something more generic. *//* w w w . ja v a 2s. c om*/ public static boolean isHiveTypeImprovised(int sqlType) { return sqlType == Types.DATE || sqlType == Types.TIME || sqlType == Types.TIMESTAMP || sqlType == Types.DECIMAL || sqlType == Types.NUMERIC; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableReadContext.java
private static void setParamVal(PreparedStatement ps, int paramIdx, int sqlType, String paramVal) throws SQLException, StageException { Utils.checkState(OffsetQueryUtil.SQL_TYPE_TO_FIELD_TYPE.containsKey(sqlType), Utils.format("Unsupported Partition Offset Type: {}", sqlType)); //All Date/Time Types are stored as long offsets //Parse string to get long. switch (sqlType) { case Types.TIME: ps.setTime(paramIdx, new java.sql.Time(Long.valueOf(paramVal))); break;/*from w w w . j ava 2 s . c o m*/ case Types.DATE: ps.setDate(paramIdx, new java.sql.Date(Long.valueOf(paramVal))); break; case Types.TIMESTAMP: Timestamp ts = TableContextUtil.getTimestampForOffsetValue(paramVal); ps.setTimestamp(paramIdx, ts); break; default: ps.setObject(paramIdx, Field.create(OffsetQueryUtil.SQL_TYPE_TO_FIELD_TYPE.get(sqlType), paramVal).getValue()); } }
From source file:RowSetModel.java
public Class getColumnClass(int column) { String cname;//from w ww. j a v a2s. co m int type; try { ResultSetMetaData meta = rowSet.getMetaData(); if (meta == null) { return null; } type = meta.getColumnType(column + 1); } catch (SQLException e) { e.printStackTrace(); return super.getColumnClass(column); } switch (type) { case Types.BIT: { cname = "java.lang.Boolean"; break; } case Types.TINYINT: { cname = "java.lang.Byte"; break; } case Types.SMALLINT: { cname = "java.lang.Short"; break; } case Types.INTEGER: { cname = "java.lang.Integer"; break; } case Types.BIGINT: { cname = "java.lang.Long"; break; } case Types.FLOAT: case Types.REAL: { cname = "java.lang.Float"; break; } case Types.DOUBLE: { cname = "java.lang.Double"; break; } case Types.NUMERIC: { cname = "java.lang.Number"; break; } case Types.DECIMAL: { cname = "java.math.BigDecimal"; break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { cname = "java.lang.String"; break; } case Types.DATE: { cname = "java.sql.Date"; break; } case Types.TIME: { cname = "java.sql.Time"; break; } case Types.TIMESTAMP: { cname = "java.sql.Timestamp"; break; } case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: { cname = "byte[]"; break; } case Types.OTHER: case Types.JAVA_OBJECT: { cname = "java.lang.Object"; break; } case Types.CLOB: { cname = "java.sql.Clob"; break; } case Types.BLOB: { cname = "java.ssql.Blob"; break; } case Types.REF: { cname = "java.sql.Ref"; break; } case Types.STRUCT: { cname = "java.sql.Struct"; break; } default: { return super.getColumnClass(column); } } try { return Class.forName(cname); } catch (Exception e) { e.printStackTrace(); return super.getColumnClass(column); } }
From source file:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java
@Parameterized.Parameters(name = "type({0})") public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true }, { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" }, { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null }, { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 }, { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 }, { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L }, { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 }, { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 }, { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) }, { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) }, { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) }, { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL, new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) }, { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" }, { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY, new byte[] { (byte) 0x00 } }, { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null }, { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null }, { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, }); }
From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java
public static String sqlTypeToHiveType(Integer type) { switch (type) { case Types.BIGINT: return "bigint"; case Types.NUMERIC: case Types.DOUBLE: case Types.DECIMAL: return "double"; case Types.INTEGER: return "int"; case Types.FLOAT: return "float"; case Types.TINYINT: return "tinyint"; case Types.DATE: return "date"; case Types.TIMESTAMP: return "timestamp"; case Types.BOOLEAN: return "boolean"; case Types.BINARY: return "binary"; default:/*from w w w .j a v a 2 s . c om*/ return "string"; } }
From source file:com.nabla.wapp.server.json.SqlColumn.java
public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException { switch (type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: record.put(label, rs.getInt(column)); break;//from w w w.ja v a2s . c o m case Types.BOOLEAN: case Types.BIT: record.put(label, rs.getBoolean(column)); break; case Types.DATE: final Date dt = rs.getDate(column); if (rs.wasNull()) record.put(label, null); else record.put(label, new JSonDate(dt)); return; case Types.TIMESTAMP: final Timestamp tm = rs.getTimestamp(column); if (rs.wasNull()) record.put(label, null); else record.put(label, timeStampFormat.format(tm)); return; case Types.DOUBLE: record.put(label, rs.getDouble(column)); break; case Types.FLOAT: record.put(label, rs.getFloat(column)); break; case Types.NULL: record.put(label, null); return; default: record.put(label, rs.getString(column)); break; } if (rs.wasNull()) record.put(label, null); }
From source file:com.trackplus.ddl.GenericStringValueConverter.java
protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType) throws SQLException, DDLException { String value = resultSet.getString(columnIdx); if (value != null) { switch (jdbcType) { case Types.NUMERIC: case Types.DECIMAL: break; case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: { break; }//w w w . ja v a 2 s. c om case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.TIME: case Types.CLOB: case Types.ARRAY: case Types.REF: { value = "'" + value.replaceAll("'", "''") + "'"; break; } case Types.DATE: case Types.TIMESTAMP: { Date d = resultSet.getDate(columnIdx); Calendar cal = Calendar.getInstance(); cal.setTime(d); int year = cal.get(Calendar.YEAR); if (year < 1900) { throw new DDLException("Invalid date:" + d); } else { value = "'" + value + "'"; } break; } case Types.BLOB: case Types.LONGVARBINARY: { Blob blobValue = resultSet.getBlob(columnIdx); String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); value = "'" + str + "'"; break; } default: break; } } return value; }
From source file:com.zousu.mongopresser.Presser.java
public void press() { //get a list of all the tables and columns logger.info("Starting MySQL to Mongo Conversion..."); logger.info("Preparing Tables..."); mySQLHandler.initialiseDatabase();//from w ww. java 2 s . co m List<Table> tables = mySQLHandler.getTableList(); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); List<Column> columns = table.getColumns(); List<DBObject> dboList = new ArrayList<DBObject>(); SqlRowSet rs = mySQLHandler.selectAllFromTable(table.getTableName()); logger.info("Creating objects for " + table.getTableName() + "..."); while (rs.next()) { BasicDBObject dbo = new BasicDBObject(); for (int j = 0; j < columns.size(); j++) { Column col = columns.get(j); String colName = col.getColumnName(); switch (col.getType()) { case Types.INTEGER: case Types.BIGINT: dbo.append(colName, rs.getInt(colName)); break; case Types.DOUBLE: dbo.append(colName, rs.getDouble(colName)); break; case Types.DATE: dbo.append(colName, rs.getDate(colName)); break; default: dbo.append(colName, rs.getString(colName)); break; } } dboList.add(dbo); } //now insert it logger.info("Inserting " + dboList.size() + " mongo rows into " + table.getTableName() + "..."); table.setNumOfRows(dboList.size()); try { mongoHandler.createCollection(table.getTableName(), true); mongoHandler.batchInsert(dboList, table.getTableName()); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == dboList.size()); logger.info(table.getTableName() + " DONE!"); } catch (CollectionExistException e) { e.printStackTrace(); } } logger.info(tables.size() + " collections added!"); //now check go get it from mongo and check if the data there is correct logger.info("Checking mongo consistency..."); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == table.getNumOfRows()); logger.info(table.getTableName() + " consistent!"); } logger.info("MySQL to Mongo Conversion Completed!!!!"); }
From source file:jongo.handler.JongoResultSetHandler.java
/** * Converts a ResultSet to a Map. Important to note that DATE, TIMESTAMP & TIME objects generate * a {@linkplain org.joda.time.DateTime} object using {@linkplain org.joda.time.format.ISODateTimeFormat}. * @param resultSet a {@linkplain java.sql.ResultSet} * @return a Map with the column names as keys and the values. null if something goes wrong. */// w w w. j av a 2s . c o m public static Map<String, String> resultSetToMap(ResultSet resultSet) { Map<String, String> map = new HashMap<String, String>(); try { int columnCount = resultSet.getMetaData().getColumnCount(); l.trace("Mapping a result set with " + columnCount + " columns to a Map"); ResultSetMetaData meta = resultSet.getMetaData(); for (int i = 1; i < columnCount + 1; i++) { String colName = meta.getColumnName(i).toLowerCase(); int colType = meta.getColumnType(i); String v = resultSet.getString(i); if (colType == Types.DATE) { v = new DateTime(resultSet.getDate(i)).toString(dateFTR); l.trace("Mapped DATE column " + colName + " with value : " + v); } else if (colType == Types.TIMESTAMP) { v = new DateTime(resultSet.getTimestamp(i)).toString(dateTimeFTR); l.trace("Mapped TIMESTAMP column " + colName + " with value : " + v); } else if (colType == Types.TIME) { v = new DateTime(resultSet.getTimestamp(i)).toString(timeFTR); l.trace("Mapped TIME column " + colName + " with value : " + v); } else { l.trace("Mapped " + meta.getColumnTypeName(i) + " column " + colName + " with value : " + v); } map.put(colName, v); } } catch (SQLException e) { l.error("Failed to map ResultSet"); l.error(e.getMessage()); return null; } return map; }
From source file:au.com.ish.derbydump.derbydump.metadata.Column.java
/** * Get a string value for the value in this column in the datarow * /*from ww w . j a v a2 s . c o m*/ * @param dataRow The row which we are exporting * @return an SQL statement compliant string version of the value */ public String toString(ResultSet dataRow) throws SQLException { switch (getColumnDataType()) { case Types.BINARY: case Types.VARBINARY: case Types.BLOB: { Blob obj = dataRow.getBlob(columnName); return (obj == null) ? "NULL" : processBinaryData(obj); } case Types.CLOB: { Clob obj = dataRow.getClob(columnName); return (obj == null) ? "NULL" : processClobData(obj); } case Types.CHAR: case Types.LONGNVARCHAR: case Types.VARCHAR: { String obj = dataRow.getString(columnName); return (obj == null) ? "NULL" : processStringData(obj); } case Types.TIME: { Time obj = dataRow.getTime(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.DATE: { Date obj = dataRow.getDate(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.TIMESTAMP: { Timestamp obj = dataRow.getTimestamp(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.SMALLINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.BIGINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.INTEGER: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.NUMERIC: case Types.DECIMAL: { BigDecimal obj = dataRow.getBigDecimal(columnName); return (obj == null) ? "NULL" : String.valueOf(obj); } case Types.REAL: case Types.FLOAT: { Float obj = dataRow.getFloat(columnName); // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } case Types.DOUBLE: { Double obj = dataRow.getDouble(columnName); return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } default: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } } }