List of usage examples for java.sql Types CLOB
int CLOB
To view the source code for java.sql Types CLOB.
Click Source Link
CLOB
. From source file:org.apache.openjpa.jdbc.schema.Column.java
/** * Return true if this column is compatible with the given JDBC type * from {@link Types} and size.//from w w w .j a v a2 s. co m */ public boolean isCompatible(int type, String typeName, int size, int decimals) { if (type == Types.OTHER || getType() == Types.OTHER) return true; // note that the given size is currently ignored, but may be useful // to dynamically-populating subclasses switch (getType()) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: switch (type) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return true; default: return false; } case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: switch (type) { case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: return true; default: return false; } case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: switch (type) { case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: switch (type) { case Types.LONGVARCHAR: case Types.CLOB: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case 2007: // Oracle-defined opaque type code for XMLType switch (type) { case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CLOB: case Types.BLOB: return true; default: return false; } default: return type == getType(); } }
From source file:org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereTriggerTemplate.java
@Override protected String buildKeyVariablesDeclare(Column[] columns, String prefix) { String text = ""; for (int i = 0; i < columns.length; i++) { text += "declare @" + prefix + "pk" + i + " "; switch (columns[i].getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: text += "bigint\n"; break; case Types.NUMERIC: case Types.DECIMAL: text += "decimal\n"; break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: text += "float\n"; break; case Types.CHAR: case Types.VARCHAR: case ColumnTypes.NVARCHAR: case ColumnTypes.LONGNVARCHAR: case Types.LONGVARCHAR: text += "varchar(1000)\n"; break; case Types.DATE: text += "date\n"; break; case Types.TIME: text += "time\n"; break; case Types.TIMESTAMP: text += "datetime\n"; break; case Types.BOOLEAN: case Types.BIT: text += "bit\n"; break; case Types.CLOB: text += "varchar(16384)\n"; break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case -10: // SQL-Server ntext binary type text += "varbinary(16384)\n"; break; case Types.OTHER: text += "varbinary(16384)\n"; break; default://from ww w . j av a 2s . co m if (columns[i].getJdbcTypeName() != null && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) { text += "interval"; break; } throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType()); } } return text; }
From source file:org.sakaiproject.warehouse.util.db.DbLoader.java
protected int getJavaSqlType(String genericDataTypeName) { // Find the type code for this generic type name int dataTypeCode = 0; if (genericDataTypeName.equalsIgnoreCase("BIT")) dataTypeCode = Types.BIT; // -7 else if (genericDataTypeName.equalsIgnoreCase("TINYINT")) dataTypeCode = Types.TINYINT; // -6 else if (genericDataTypeName.equalsIgnoreCase("SMALLINT")) dataTypeCode = Types.SMALLINT; // 5 else if (genericDataTypeName.equalsIgnoreCase("INTEGER")) dataTypeCode = Types.INTEGER; // 4 else if (genericDataTypeName.equalsIgnoreCase("BIGINT")) dataTypeCode = Types.BIGINT; // -5 else if (genericDataTypeName.equalsIgnoreCase("FLOAT")) dataTypeCode = Types.FLOAT; // 6 else if (genericDataTypeName.equalsIgnoreCase("REAL")) dataTypeCode = Types.REAL; // 7 else if (genericDataTypeName.equalsIgnoreCase("DOUBLE")) dataTypeCode = Types.DOUBLE; // 8 else if (genericDataTypeName.equalsIgnoreCase("NUMERIC")) dataTypeCode = Types.NUMERIC; // 2 else if (genericDataTypeName.equalsIgnoreCase("DECIMAL")) dataTypeCode = Types.DECIMAL; // 3 else if (genericDataTypeName.equalsIgnoreCase("CHAR")) dataTypeCode = Types.CHAR; // 1 else if (genericDataTypeName.equalsIgnoreCase("VARCHAR")) dataTypeCode = Types.VARCHAR; // 12 else if (genericDataTypeName.equalsIgnoreCase("LONGVARCHAR")) dataTypeCode = Types.LONGVARCHAR; // -1 else if (genericDataTypeName.equalsIgnoreCase("DATE")) dataTypeCode = Types.DATE; // 91 else if (genericDataTypeName.equalsIgnoreCase("TIME")) dataTypeCode = Types.TIME; // 92 else if (genericDataTypeName.equalsIgnoreCase("TIMESTAMP")) dataTypeCode = Types.TIMESTAMP; // 93 else if (genericDataTypeName.equalsIgnoreCase("BINARY")) dataTypeCode = Types.BINARY; // -2 else if (genericDataTypeName.equalsIgnoreCase("VARBINARY")) dataTypeCode = Types.VARBINARY; // -3 else if (genericDataTypeName.equalsIgnoreCase("LONGVARBINARY")) dataTypeCode = Types.LONGVARBINARY; // -4 else if (genericDataTypeName.equalsIgnoreCase("NULL")) dataTypeCode = Types.NULL; // 0 else if (genericDataTypeName.equalsIgnoreCase("OTHER")) dataTypeCode = Types.OTHER; // 1111 else if (genericDataTypeName.equalsIgnoreCase("JAVA_OBJECT")) dataTypeCode = Types.JAVA_OBJECT; // 2000 else if (genericDataTypeName.equalsIgnoreCase("DISTINCT")) dataTypeCode = Types.DISTINCT; // 2001 else if (genericDataTypeName.equalsIgnoreCase("STRUCT")) dataTypeCode = Types.STRUCT; // 2002 else if (genericDataTypeName.equalsIgnoreCase("ARRAY")) dataTypeCode = Types.ARRAY; // 2003 else if (genericDataTypeName.equalsIgnoreCase("BLOB")) dataTypeCode = Types.BLOB; // 2004 else if (genericDataTypeName.equalsIgnoreCase("CLOB")) dataTypeCode = Types.CLOB; // 2005 else if (genericDataTypeName.equalsIgnoreCase("REF")) dataTypeCode = Types.REF; // 2006 return dataTypeCode; }
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 ww .j av a 2 s . co 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:CSVWriter.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//w ww . jav a 2 s.c o m case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.apache.openjpa.persistence.jdbc.XMLPersistenceMappingParser.java
/** * Extend to set the columns.//from w ww . j a v a 2 s. c o m */ @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: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 w w w . j a v a2 s . co m * @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:org.batoo.jpa.core.jdbc.adapter.JdbcAdaptor.java
/** * Returns the data type of the column./*w w w . java2 s. com*/ * * @param cd * the column definition * @param sqlType * the sql type * @return the data type * * @since $version * @author hceylan */ protected String getColumnType(AbstractColumn cd, int sqlType) { switch (sqlType) { case Types.BLOB: return "BLOB(" + cd.getLength() + ")"; case Types.CLOB: return "CLOB(" + cd.getLength() + ")"; case Types.VARCHAR: return "VARCHAR(" + cd.getLength() + ")"; case Types.TIME: return "TIME"; case Types.DATE: return "DATE"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.CHAR: return "CHAR"; case Types.BOOLEAN: return "BOOLEAN"; case Types.TINYINT: case Types.SMALLINT: return "SMALLINT"; case Types.INTEGER: return "INTEGER"; case Types.BIGINT: return "BIGINT"; case Types.FLOAT: return "FLOAT" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DOUBLE: return "DOUBLE" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DECIMAL: return "DECIMAL" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + (cd.getScale() > 0 ? "," + cd.getScale() : "") + ")" : ""); } throw new IllegalArgumentException("Unhandled sql type: " + sqlType); }
From source file:org.apache.torque.util.BasePeerImpl.java
/** * Inserts a record into a database table. * <p>/*from w w w .java2s . c om*/ * If the primary key is included in Criteria, then that value will * be used to insert the row. * <p> * Otherwise, if the primary key can be generated automatically, * the generated key will be used for the insert and will be returned. * <p> * If no value is given for the primary key is defined and it cannot * be generated automatically or the table has no primary key, * the values will be inserted as specified and null will be returned. * * @param insertValues Contains the values to insert, not null. * @param connection the connection to use for the insert, not null. * * @return the primary key of the inserted row (if the table * has a primary key) or null (if the table does not have * a primary key). * * @throws TorqueException if a database error occurs. */ public ObjectKey doInsert(ColumnValues insertValues, Connection connection) throws TorqueException { if (insertValues == null) { throw new TorqueException("insertValues is null"); } if (connection == null) { throw new TorqueException("connection is null"); } String databaseNameFromInsertValues = insertValues.getDbName(); if (databaseNameFromInsertValues == null) { databaseNameFromInsertValues = getDatabaseName(); } Database database = Torque.getDatabase(databaseNameFromInsertValues); Object keyInfo = getIdMethodInfo(); IdGenerator keyGen = database.getIdGenerator(getTableMap().getPrimaryKeyMethod()); SimpleKey id = null; // can currently generate only single column pks, therefore a single // columnMap is ok ColumnMap primaryKey = null; if (keyGen != null) { // fail on multiple pks primaryKey = getTableMap().getPrimaryKey(); // primaryKey will be null if there is no primary key // defined for the table we're inserting into. if (keyGen.isPriorToInsert() && primaryKey != null && !insertValues.containsKey(primaryKey)) { id = getId(primaryKey, keyGen, connection, keyInfo); insertValues.put(primaryKey, new JdbcTypedValue(id.getValue(), id.getJdbcType())); } } List<String> columnNames = new ArrayList<String>(); List<JdbcTypedValue> replacementObjects = new ArrayList<JdbcTypedValue>(); for (Map.Entry<Column, JdbcTypedValue> columnValue : insertValues.entrySet()) { Column column = columnValue.getKey(); columnNames.add(column.getColumnName()); JdbcTypedValue value = columnValue.getValue(); replacementObjects.add(value); } String fullTableName = SqlBuilder.getFullTableName(getTableMap().getFullyQualifiedTableName(), databaseNameFromInsertValues); StringBuilder query = new StringBuilder("INSERT INTO ").append(fullTableName).append("(") .append(StringUtils.join(columnNames, ",")).append(") VALUES ("); for (int i = 0; i < columnNames.size(); ++i) { if (i != 0) { query.append(","); } query.append("?"); } query.append(")"); PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(query.toString()); int position = 1; for (JdbcTypedValue replacementObject : replacementObjects) { Object value = replacementObject.getValue(); if (value != null) { if (replacementObject.getJdbcType() != Types.BLOB && replacementObject.getJdbcType() != Types.CLOB) { preparedStatement.setObject(position, value, replacementObject.getJdbcType()); } else { preparedStatement.setObject(position, value); } } else { preparedStatement.setNull(position, replacementObject.getJdbcType()); } position++; } long startTime = System.currentTimeMillis(); log.debug("Executing insert " + query.toString() + " using parameters " + replacementObjects); preparedStatement.executeUpdate(); long queryEndTime = System.currentTimeMillis(); log.trace("insert took " + (queryEndTime - startTime) + " milliseconds"); preparedStatement.close(); preparedStatement = null; } catch (SQLException e) { throw ExceptionMapper.getInstance().toTorqueException(e); } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException e) { log.warn("error closing prepared statement", e); } } } // If the primary key column is auto-incremented, get the id // now. if (keyGen != null && keyGen.isPostInsert() && primaryKey != null && !insertValues.containsKey(primaryKey)) { id = getId(primaryKey, keyGen, connection, keyInfo); } return id; }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
public boolean isClob(int type) { return type == Types.CLOB || type == Types.LONGVARCHAR || type == ColumnTypes.LONGNVARCHAR; }