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:org.apache.torque.engine.database.model.TypeMap.java
/** * Initializes the SQL to Java map so that it * can be used by client code.//w ww . j a v a 2s . com */ public static synchronized void initialize() { if (!isInitialized) { // Create JDBC -> Java object mappings. jdbcToJavaObjectMap = new Hashtable(); jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE); // Create JDBC -> native Java type mappings. jdbcToJavaNativeMap = new Hashtable(); jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE); jdbcToJavaNativeObjectMap = new Hashtable(); jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_OBJECT_TYPE); // Create JDBC -> Village asX() mappings. jdbcToVillageMethodMap = new Hashtable(); jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD); jdbcToVillageObjectMethodMap = new Hashtable(); jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_OBJECT_METHOD); // Create JDBC -> ParameterParser getX() mappings. jdbcToPPMethodMap = new Hashtable(); jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD); // Create JDBC -> Java object mappings. torqueTypeToJdbcTypeMap = new Hashtable(); Iterator iter = SchemaType.iterator(); while (iter.hasNext()) { SchemaType type = (SchemaType) iter.next(); torqueTypeToJdbcTypeMap.put(type, type); } torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR); torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER); // Create JDBC type code to torque type map. jdbcToTorqueTypeMap = new Hashtable(); jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR); jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB); jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC); jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL); jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT); jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT); jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT); jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER); jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT); jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL); jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT); jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE); jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY); jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB); jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE); jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME); jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP); isInitialized = true; } }
From source file:org.apache.sqoop.manager.OracleManager.java
@Override public String datetimeToQueryString(String datetime, int columnType) { if (columnType == Types.TIMESTAMP) { return "TO_TIMESTAMP('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS.FF')"; } else if (columnType == Types.DATE) { return "TO_DATE('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS')"; } else {//from ww w. j a va 2 s . c om String msg = "Column type is neither timestamp nor date!"; LOG.error(msg); throw new RuntimeException(msg); } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set the values from the Json node to the current object (no database access) * //from w w w . j a v a2 s. c o m * @param node * @param ignorePrimaryKey * True will ignore primaryKey from Json * @throws WaarpDatabaseSqlException */ public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException { DbValue[] list = allFields; if (ignorePrimaryKey) { list = otherFields; } for (DbValue value : list) { if (value.column.equalsIgnoreCase("UPDATEDINFO")) { continue; } JsonNode item = node.get(value.column); if (item != null && !item.isMissingNode() && !item.isNull()) { isSaved = false; switch (value.type) { case Types.VARCHAR: case Types.LONGVARCHAR: value.setValue(item.asText()); break; case Types.BIT: value.setValue(item.asBoolean()); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value.setValue(item.asInt()); break; case Types.BIGINT: value.setValue(item.asLong()); break; case Types.REAL: case Types.DOUBLE: value.setValue(item.asDouble()); break; case Types.VARBINARY: try { value.setValue(item.binaryValue()); } catch (IOException e) { throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e); } break; case Types.DATE: value.setValue(new Date(item.asLong())); break; case Types.TIMESTAMP: value.setValue(new Timestamp(item.asLong())); break; case Types.CLOB: case Types.BLOB: default: throw new WaarpDatabaseSqlException("Unsupported type: " + value.type); } } } setFromArray(); }
From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java
/** * This method bind values to prepared statement. * * @param type data Type// w ww.j a va 2s . c om * @param value String value * @param ordinalPosition Ordinal Position * @param sqlStatement Statement * @throws SQLException * @throws ParseException * @throws ODataServiceFault */ private void bindValuesToPreparedStatement(int type, String value, int ordinalPosition, PreparedStatement sqlStatement) throws SQLException, ParseException, ODataServiceFault { byte[] data; try { switch (type) { case Types.INTEGER: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setInt(ordinalPosition, ConverterUtil.convertToInt(value)); } break; case Types.TINYINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setByte(ordinalPosition, ConverterUtil.convertToByte(value)); } break; case Types.SMALLINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setShort(ordinalPosition, ConverterUtil.convertToShort(value)); } break; case Types.DOUBLE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDouble(ordinalPosition, ConverterUtil.convertToDouble(value)); } break; case Types.VARCHAR: /* fall through */ case Types.CHAR: /* fall through */ case Types.LONGVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; case Types.CLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BOOLEAN: /* fall through */ case Types.BIT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBoolean(ordinalPosition, ConverterUtil.convertToBoolean(value)); } break; case Types.BLOB: /* fall through */ case Types.LONGVARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBlob(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.BINARY: /* fall through */ case Types.VARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBinaryStream(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.DATE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDate(ordinalPosition, DBUtils.getDate(value)); } break; case Types.DECIMAL: /* fall through */ case Types.NUMERIC: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBigDecimal(ordinalPosition, ConverterUtil.convertToBigDecimal(value)); } break; case Types.FLOAT: /* fall through */ case Types.REAL: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setFloat(ordinalPosition, ConverterUtil.convertToFloat(value)); } break; case Types.TIME: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTime(ordinalPosition, DBUtils.getTime(value)); } break; case Types.LONGNVARCHAR: /* fall through */ case Types.NCHAR: /* fall through */ case Types.NVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNString(ordinalPosition, value); } break; case Types.NCLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BIGINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setLong(ordinalPosition, ConverterUtil.convertToLong(value)); } break; case Types.TIMESTAMP: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTimestamp(ordinalPosition, DBUtils.getTimestamp(value)); } break; default: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; } } catch (DataServiceFault e) { throw new ODataServiceFault(e, "Error occurred while binding values. :" + e.getMessage()); } }
From source file:org.pentaho.platform.plugin.action.jfreereport.JFreeReportGeneratorComponent.java
public int getType(final Class typeClass) { if (typeClass != null) { if (typeClass.getName().equals(String.class.getName())) { return Types.VARCHAR; } else if (typeClass.getName().equals(BigDecimal.class.getName()) || typeClass.getName().equals(Integer.class.getName())) { return Types.NUMERIC; } else if (typeClass.getName().equals(Date.class.getName())) { return Types.DATE; }/*from w w w . j ava 2 s.c om*/ } return Types.VARCHAR; }
From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java
/** * Get a ConstantNode to represent a typed null value. * * @param type Type of the null node./*from ww w. ja va 2 s . com*/ * @throws StandardException Thrown on error * @return A ConstantNode with the specified type, and a value of null */ public ConstantNode getNullNode(DataTypeDescriptor type) throws StandardException { int constantNodeType; switch (type.getTypeId().getJDBCTypeId()) { case Types.VARCHAR: constantNodeType = C_NodeTypes.VARCHAR_CONSTANT_NODE; break; case Types.CHAR: constantNodeType = C_NodeTypes.CHAR_CONSTANT_NODE; break; case Types.TINYINT: constantNodeType = C_NodeTypes.TINYINT_CONSTANT_NODE; break; case Types.SMALLINT: constantNodeType = C_NodeTypes.SMALLINT_CONSTANT_NODE; break; case Types.INTEGER: constantNodeType = C_NodeTypes.INT_CONSTANT_NODE; break; case Types.BIGINT: constantNodeType = C_NodeTypes.LONGINT_CONSTANT_NODE; break; case Types.REAL: constantNodeType = C_NodeTypes.FLOAT_CONSTANT_NODE; break; case Types.DOUBLE: constantNodeType = C_NodeTypes.DOUBLE_CONSTANT_NODE; break; case Types.NUMERIC: case Types.DECIMAL: constantNodeType = C_NodeTypes.DECIMAL_CONSTANT_NODE; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE; break; case Types.BINARY: constantNodeType = C_NodeTypes.BIT_CONSTANT_NODE; break; case Types.VARBINARY: constantNodeType = C_NodeTypes.VARBIT_CONSTANT_NODE; break; case Types.LONGVARCHAR: constantNodeType = C_NodeTypes.LONGVARCHAR_CONSTANT_NODE; break; case Types.CLOB: constantNodeType = C_NodeTypes.CLOB_CONSTANT_NODE; break; case Types.LONGVARBINARY: constantNodeType = C_NodeTypes.LONGVARBIT_CONSTANT_NODE; break; case Types.BLOB: constantNodeType = C_NodeTypes.BLOB_CONSTANT_NODE; break; case JDBC40Translation.SQLXML: constantNodeType = C_NodeTypes.XML_CONSTANT_NODE; break; case Types.BOOLEAN: constantNodeType = C_NodeTypes.BOOLEAN_CONSTANT_NODE; break; default: if (type.getTypeId().userType()) { constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE; } else { throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE, type.getTypeId().getSQLTypeName()); } } ConstantNode constantNode = (ConstantNode) getNodeFactory().getNode(constantNodeType, type.getTypeId(), cm); constantNode.setType(type.getNullabilityType(true)); return constantNode; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Converts the given SQL type to a value type. * * @param sqlType The sql type to be converted. * * @return The value type that fits the given sql type. *//*from w w w .ja v a 2 s . co m*/ private static ValueType sqlTypeToValueType(int sqlType) { ValueType valueType; switch (sqlType) { case Types.BOOLEAN: case Types.BIT: { valueType = ValueType.BOOLEAN; break; } case Types.CHAR: case Types.VARCHAR: valueType = ValueType.TEXT; break; case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.REAL: case Types.NUMERIC: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: valueType = ValueType.NUMBER; break; case Types.DATE: valueType = ValueType.DATE; break; case Types.TIME: valueType = ValueType.TIMEOFDAY; break; case Types.TIMESTAMP: valueType = ValueType.DATETIME; break; default: valueType = ValueType.TEXT; break; } return valueType; }
From source file:org.fastcatsearch.datasource.reader.DBReader.java
@Override public SchemaSetting getAutoGeneratedSchemaSetting() { Map<String, String> properties = singleSourceConfig.getProperties(); String jdbcSourceId = properties.get("jdbcSourceId"); String dataSQL = properties.get("dataSQL"); IRService service = ServiceManager.getInstance().getService(IRService.class); Connection con = null;/* w w w .j a v a2 s . c o m*/ PreparedStatement pst = null; ResultSet res = null; ResultSetMetaData meta = null; try { JDBCSourceInfo jdbcInfo = service.getJDBCSourceInfo(jdbcSourceId); if (jdbcInfo != null) { con = getConnection(jdbcInfo); } logger.trace("get jdbc connection : {}", con); if (con != null) { logger.trace("executing sql :{}", dataSQL); pst = con.prepareStatement(dataSQL); pst.setFetchSize(1); pst.setMaxRows(1); res = pst.executeQuery(); res.next(); meta = res.getMetaData(); SchemaSetting setting = new SchemaSetting(); PrimaryKeySetting primaryKeySetting = new PrimaryKeySetting(); List<FieldSetting> fieldSettingList = new ArrayList<FieldSetting>(); List<AnalyzerSetting> analyzerSetting = new ArrayList<AnalyzerSetting>(); List<GroupIndexSetting> groupIndexSetting = new ArrayList<GroupIndexSetting>(); List<IndexSetting> indexSetting = new ArrayList<IndexSetting>(); List<FieldIndexSetting> fieldIndexSetting = new ArrayList<FieldIndexSetting>(); logger.trace("columnCount:{}", meta.getColumnCount()); String tableName = null; for (int inx = 0; inx < meta.getColumnCount(); inx++) { if (tableName == null) { tableName = meta.getTableName(inx + 1); } FieldSetting field = new FieldSetting(); Type type = null; int size = 0; switch (meta.getColumnType(inx + 1)) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: type = Type.INT; break; case Types.BIGINT: type = Type.LONG; break; case Types.FLOAT: type = Type.FLOAT; break; case Types.DOUBLE: type = Type.DOUBLE; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: type = Type.DATETIME; break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: type = Type.STRING; break; default: type = Type.STRING; break; } field.setId(meta.getColumnLabel(inx + 1)); field.setName(field.getId()); field.setType(type); field.setSize(size); logger.trace("field add {}", field); fieldSettingList.add(field); } setting.setFieldSettingList(fieldSettingList); setting.setPrimaryKeySetting(primaryKeySetting); setting.setFieldIndexSettingList(fieldIndexSetting); setting.setAnalyzerSettingList(analyzerSetting); setting.setGroupIndexSettingList(groupIndexSetting); setting.setIndexSettingList(indexSetting); return setting; } } catch (IRException e) { logger.error("", e); } catch (SQLException e) { logger.error("", e); } finally { if (res != null) try { res.close(); } catch (SQLException ignore) { } if (pst != null) try { pst.close(); } catch (SQLException ignore) { } if (con != null) try { con.close(); } catch (SQLException ignore) { } } return null; }
From source file:org.apache.openjpa.persistence.jdbc.XMLPersistenceMappingParser.java
/** * Extend to set the columns.//from ww w . j a va 2s . c om */ @Override protected void endFieldMapping(FieldMetaData field) throws SAXException { // setup columns with cached lob and temporal info FieldMapping fm = (FieldMapping) field; if (_lob || _temporal != null) { int typeCode = fm.isElementCollection() ? fm.getElement().getDeclaredTypeCode() : fm.getDeclaredTypeCode(); Class<?> type = fm.isElementCollection() ? fm.getElement().getDeclaredType() : fm.getDeclaredType(); if (_cols == null) { _cols = new ArrayList<Column>(1); _cols.add(new Column()); } for (Column col : _cols) { if (_lob && (typeCode == JavaTypes.STRING || type == char[].class || type == Character[].class)) { col.setSize(-1); col.setType(Types.CLOB); } else if (_lob) col.setType(Types.BLOB); else { switch (_temporal) { case DATE: col.setType(Types.DATE); break; case TIME: col.setType(Types.TIME); break; case TIMESTAMP: col.setType(Types.TIMESTAMP); break; } } } } if (_cols != null) { switch (fm.getDeclaredTypeCode()) { case JavaTypes.ARRAY: Class<?> type = fm.getDeclaredType(); if (type == byte[].class || type == Byte[].class || type == char[].class || type == Character[].class) { fm.getValueInfo().setColumns(_cols); break; } // else no break case JavaTypes.COLLECTION: if (!fm.getValue().isSerialized()) { fm.getElementMapping().getValueInfo().setColumns(_cols); } else { fm.getValueInfo().setColumns(_cols); } break; case JavaTypes.MAP: fm.getElementMapping().getValueInfo().setColumns(_cols); break; default: fm.getValueInfo().setColumns(_cols); } if (_colTable != null) fm.getMappingInfo().setTableIdentifier(DBIdentifier.newTable(_colTable, delimit())); setUnique(fm); } clearColumnInfo(); }
From source file:org.executequery.databasemediators.spi.DefaultStatementExecutor.java
/** <p>Executes the specified procedure. * * @param the SQL procedure to execute * @return the query result/*from ww w. j a va 2s . c o m*/ */ public SqlStatementResult execute(DatabaseExecutable databaseExecutable) throws SQLException { if (!prepared()) { return statementResult; } ProcedureParameter[] param = databaseExecutable.getParametersArray(); Arrays.sort(param, new ProcedureParameterSorter()); String procQuery = null; boolean hasOut = false; boolean hasParameters = (param != null && param.length > 0); List<ProcedureParameter> outs = null; List<ProcedureParameter> ins = null; if (hasParameters) { // split the params into ins and outs outs = new ArrayList<ProcedureParameter>(); ins = new ArrayList<ProcedureParameter>(); int type = -1; for (int i = 0; i < param.length; i++) { type = param[i].getType(); if (type == DatabaseMetaData.procedureColumnIn || type == DatabaseMetaData.procedureColumnInOut) { // add to the ins list ins.add(param[i]); } else if (type == DatabaseMetaData.procedureColumnOut || type == DatabaseMetaData.procedureColumnResult || type == DatabaseMetaData.procedureColumnReturn || type == DatabaseMetaData.procedureColumnUnknown || type == DatabaseMetaData.procedureColumnInOut) { // add to the outs list outs.add(param[i]); } } char QUESTION_MARK = '?'; String COMMA = ", "; // init the string buffer StringBuilder sb = new StringBuilder("{ "); if (!outs.isEmpty()) { // build the out params place holders for (int i = 0, n = outs.size(); i < n; i++) { sb.append(QUESTION_MARK); if (i < n - 1) { sb.append(COMMA); } } sb.append(" = "); } sb.append(" call "); if (databaseExecutable.supportCatalogOrSchemaInFunctionOrProcedureCalls()) { String namePrefix = null; if (databaseExecutable.supportCatalogInFunctionOrProcedureCalls()) { namePrefix = databaseExecutable.getCatalogName(); } if (databaseExecutable.supportSchemaInFunctionOrProcedureCalls()) { namePrefix = databaseExecutable.getSchemaName(); } if (namePrefix != null) { sb.append(namePrefix).append('.'); } } sb.append(databaseExecutable.getName()).append("( "); // build the ins params place holders for (int i = 0, n = ins.size(); i < n; i++) { sb.append(QUESTION_MARK); if (i < n - 1) { sb.append(COMMA); } } sb.append(" ) }"); // determine if we have out params hasOut = !(outs.isEmpty()); procQuery = sb.toString(); } else { StringBuilder sb = new StringBuilder(); sb.append("{ call "); if (databaseExecutable.getSchemaName() != null) { sb.append(databaseExecutable.getSchemaName()).append('.'); } sb.append(databaseExecutable.getName()).append("( ) }"); procQuery = sb.toString(); } //Log.debug(procQuery); // null value literal String NULL = "null"; // clear any warnings conn.clearWarnings(); Log.info("Executing: " + procQuery); CallableStatement cstmnt = null; try { // prepare the statement cstmnt = conn.prepareCall(procQuery); stmnt = cstmnt; } catch (SQLException e) { handleException(e); statementResult.setSqlException(e); return statementResult; } // check if we are passing parameters if (hasParameters) { // the parameter index counter int index = 1; // the java.sql.Type value int dataType = -1; // the parameter input value String value = null; // register the out params for (int i = 0, n = outs.size(); i < n; i++) { //Log.debug("setting out at index: " + index); cstmnt.registerOutParameter(index, outs.get(i).getDataType()); index++; } try { // register the in params for (int i = 0, n = ins.size(); i < n; i++) { ProcedureParameter procedureParameter = ins.get(i); value = procedureParameter.getValue(); dataType = procedureParameter.getDataType(); // try infer a type if OTHER if (dataType == Types.OTHER) { // checking only for bit/bool for now if (isTrueFalse(value)) { dataType = Types.BOOLEAN; } else if (isBit(value)) { dataType = Types.BIT; value = value.substring(2, value.length() - 1); } } if (MiscUtils.isNull(value) || value.equalsIgnoreCase(NULL)) { cstmnt.setNull(index, dataType); } else { switch (dataType) { case Types.TINYINT: byte _byte = Byte.valueOf(value).byteValue(); cstmnt.setShort(index, _byte); break; case Types.SMALLINT: short _short = Short.valueOf(value).shortValue(); cstmnt.setShort(index, _short); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: cstmnt.setString(index, value); break; case Types.BIT: case Types.BOOLEAN: boolean _boolean = false; if (NumberUtils.isNumber(value)) { int number = Integer.valueOf(value); if (number > 0) { _boolean = true; } } else { _boolean = Boolean.valueOf(value).booleanValue(); } cstmnt.setBoolean(index, _boolean); break; case Types.BIGINT: long _long = Long.valueOf(value).longValue(); cstmnt.setLong(index, _long); break; case Types.INTEGER: int _int = Integer.valueOf(value).intValue(); cstmnt.setInt(index, _int); break; case Types.REAL: float _float = Float.valueOf(value).floatValue(); cstmnt.setFloat(index, _float); break; case Types.NUMERIC: case Types.DECIMAL: cstmnt.setBigDecimal(index, new BigDecimal(value)); break; /* case Types.DATE: case Types.TIMESTAMP: case Types.TIME: cstmnt.setTimestamp(index, new Timestamp( BigDecimal(value)); */ case Types.FLOAT: case Types.DOUBLE: double _double = Double.valueOf(value).doubleValue(); cstmnt.setDouble(index, _double); break; default: cstmnt.setObject(index, value); } } // increment the index index++; } } catch (Exception e) { statementResult.setOtherErrorMessage(e.getClass().getName() + ": " + e.getMessage()); return statementResult; } } /* test creating function for postgres: CREATE FUNCTION concat_lower_or_upper(a text, b text, uppercase boolean DEFAULT false) RETURNS text AS $$ SELECT CASE WHEN $3 THEN UPPER($1 || ' ' || $2) ELSE LOWER($1 || ' ' || $2) END; $$ LANGUAGE SQL IMMUTABLE STRICT; */ try { cstmnt.clearWarnings(); boolean hasResultSet = cstmnt.execute(); Map<String, Object> results = new HashMap<String, Object>(); if (hasOut) { // incrementing index int index = 1; // return value from each registered out String returnValue = null; for (int i = 0; i < param.length; i++) { int type = param[i].getType(); int dataType = param[i].getDataType(); if (type == DatabaseMetaData.procedureColumnOut || type == DatabaseMetaData.procedureColumnResult || type == DatabaseMetaData.procedureColumnReturn || type == DatabaseMetaData.procedureColumnUnknown || type == DatabaseMetaData.procedureColumnInOut) { switch (dataType) { case Types.TINYINT: returnValue = Byte.toString(cstmnt.getByte(index)); break; case Types.SMALLINT: returnValue = Short.toString(cstmnt.getShort(index)); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: returnValue = cstmnt.getString(index); break; case Types.BIT: case Types.BOOLEAN: returnValue = Boolean.toString(cstmnt.getBoolean(index)); break; case Types.INTEGER: returnValue = Integer.toString(cstmnt.getInt(index)); break; case Types.BIGINT: returnValue = Long.toString(cstmnt.getLong(index)); break; case Types.REAL: returnValue = Float.toString(cstmnt.getFloat(index)); break; case Types.NUMERIC: case Types.DECIMAL: returnValue = cstmnt.getBigDecimal(index).toString(); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: returnValue = cstmnt.getDate(index).toString(); break; case Types.FLOAT: case Types.DOUBLE: returnValue = Double.toString(cstmnt.getDouble(index)); break; } if (returnValue == null) { returnValue = "NULL"; } results.put(param[i].getName(), returnValue); index++; } } } if (!hasResultSet) { statementResult.setUpdateCount(cstmnt.getUpdateCount()); } else { statementResult.setResultSet(cstmnt.getResultSet()); } useCount++; statementResult.setOtherResult(results); } catch (SQLException e) { statementResult.setSqlException(e); } catch (Exception e) { statementResult.setMessage(e.getMessage()); } return statementResult; }