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.jumpmind.db.platform.mssql.MsSqlDdlReader.java
protected Integer mapUnknownJdbcTypeForColumn(Map<String, Object> values) { String typeName = (String) values.get("TYPE_NAME"); int size = -1; String columnSize = (String) values.get("COLUMN_SIZE"); if (isNotBlank(columnSize)) { size = Integer.parseInt(columnSize); }/*from w ww.j ava 2 s . c o m*/ if (typeName != null && typeName.toLowerCase().startsWith("text")) { return Types.LONGVARCHAR; } else if (typeName != null && typeName.toLowerCase().startsWith("ntext")) { return Types.CLOB; } else if (typeName != null && typeName.toUpperCase().contains(TypeMap.GEOMETRY)) { return Types.VARCHAR; } else if (typeName != null && typeName.toUpperCase().contains("VARCHAR") && size > 8000) { return Types.LONGVARCHAR; } else if (typeName != null && typeName.toUpperCase().contains("NVARCHAR") && size > 8000) { return Types.LONGNVARCHAR; } else if (typeName != null && typeName.toUpperCase().equals("SQL_VARIANT")) { return Types.BINARY; } else { return super.mapUnknownJdbcTypeForColumn(values); } }
From source file:com.feedzai.commons.sql.abstraction.engine.impl.OracleEngine.java
@Override protected int entityToPreparedStatement(final DbEntity entity, final PreparedStatement ps, final EntityEntry entry, final boolean useAutoInc) throws DatabaseEngineException { int i = 1;/*from www .ja va 2s .c o m*/ for (DbColumn column : entity.getColumns()) { if (column.isAutoInc() && useAutoInc) { continue; } try { final Object val; if (column.isDefaultValueSet() && !entry.containsKey(column.getName())) { val = column.getDefaultValue().getConstant(); } else { val = entry.get(column.getName()); } switch (column.getDbColumnType()) { case BLOB: ps.setBytes(i, objectToArray(val)); break; case CLOB: if (val == null) { ps.setNull(i, Types.CLOB); break; } if (val instanceof String) { StringReader sr = new StringReader((String) val); ps.setClob(i, sr); } else { throw new DatabaseEngineException("Cannot convert " + val.getClass().getSimpleName() + " to String. CLOB columns only accept Strings."); } break; case BOOLEAN: Boolean b = (Boolean) val; if (b == null) { ps.setObject(i, null); } else if (b) { ps.setObject(i, "1"); } else { ps.setObject(i, "0"); } break; default: ps.setObject(i, ensureNoUnderflow(val)); } } catch (Exception ex) { throw new DatabaseEngineException("Error while mapping variables to database", ex); } i++; } return i - 1; }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) { // Oracle internal conversions if (expected == Types.DOUBLE && actual == Types.FLOAT) { return true; }/* w w w. j a v a2 s . co m*/ if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.BIT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 1) { return true; } if (expected == Types.TINYINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 3) { return true; } if (expected == Types.INTEGER && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 10) { return true; } if (expected == Types.BIGINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 19) { return true; } // CLOB vs VARCHAR compatibility if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } return false; }
From source file:org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl.java
public boolean saveTask(Task t) { try {/*from ww w. jav a 2s . co m*/ if (t.getId() == null) { // if the id is not set the we are inserting a new record getJdbcTemplate().update(TASK_INSERT_QUERY, new Object[] { t.getOwner(), t.getSiteId(), t.getCreationDate(), t.getTask() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.CLOB }); } else { getJdbcTemplate().update(TASK_UPDATE_QUERY, new Object[] { t.getOwner(), t.getSiteId(), t.getTask(), t.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.CLOB, Types.BIGINT }); } } catch (DataAccessException e) { log.error("Exception: Could not add task:" + e.toString()); e.printStackTrace(); return false; } return true; }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
public static String encoding(String source, int sqlType, String sourceEncoding, String targetEncoding) { switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: case Types.CLOB: case Types.NCLOB: if (false == StringUtils.isEmpty(source)) { String fromEncoding = StringUtils.isBlank(sourceEncoding) ? "UTF-8" : sourceEncoding; String toEncoding = StringUtils.isBlank(targetEncoding) ? "UTF-8" : targetEncoding; // if (false == StringUtils.equalsIgnoreCase(fromEncoding, // toEncoding)) { try { return new String(source.getBytes(fromEncoding), toEncoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e.getMessage(), e); }//from w w w. j av a 2s. c o m // } } } return source; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: return getFromResultSetString(rs, index, column); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); }/*from w ww .jav a 2 s . co m*/ throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.sakaiproject.mailarchive.impl.conversion.ExtractXMLToColumns.java
public Object getValidateSource(String id, ResultSet rs) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); byte[] rv = null; switch (metadata.getColumnType(1)) { case Types.BLOB: Blob blob = rs.getBlob(1); if (blob != null) { rv = blob.getBytes(1L, (int) blob.length()); } else {/*from w w w.ja v a2s. c om*/ System.out.println("getValidateSource(" + id + ") blob == null"); } break; case Types.CLOB: Clob clob = rs.getClob(1); if (clob != null) { rv = clob.getSubString(1L, (int) clob.length()).getBytes(); } break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: rv = rs.getString(1).getBytes(); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: rv = rs.getBytes(1); break; } // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n"); return rv; }
From source file:org.batoo.jpa.jdbc.adapter.HsqlAdaptor.java
/** * {@inheritDoc}/*w w w .ja v a 2 s .c om*/ * */ @Override protected String getColumnType(AbstractColumn cd, int sqlType) { switch (sqlType) { case Types.BLOB: case Types.CLOB: return "VARBINARY(" + 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.openjpa.jdbc.sql.AzureDictionary.java
private Column[] getColumns(final Connection conn, final DBIdentifier schemaName, final DBIdentifier tableName, final DBIdentifier columnName) { if (DBIdentifier.isNull(tableName) && !supportsNullTableForGetColumns) { return null; }/*from ww w.jav a 2 s . c o m*/ final String sqlSchema = supportsSchemaForGetColumns ? getSchemaNameForMetadata(schemaName) : null; final String sqlTable = getTableNameForMetadata(tableName); final String sqlColumn = getColumnNameForMetadata(columnName); final List<Column> columnList = new ArrayList<Column>(); Statement stmt = null; ResultSet resultSet = null; try { stmt = conn.createStatement(); resultSet = stmt .executeQuery("EXEC sp_columns " + sqlTable + ", " + sqlSchema + ", null, " + sqlColumn); while (resultSet.next()) { final Column column = newColumn(resultSet); columnList.add(column); // for opta driver, which reports nvarchar as unknown type String typeName = column.getTypeIdentifier().getName(); if (typeName == null) { continue; } typeName = typeName.toUpperCase(); if ("NVARCHAR".equals(typeName)) { column.setType(Types.VARCHAR); } else if ("UNIQUEIDENTIFIER".equals(typeName)) { if (uniqueIdentifierAsVarbinary) { column.setType(Types.VARBINARY); } else { column.setType(Types.VARCHAR); } } else if ("NCHAR".equals(typeName)) { column.setType(Types.CHAR); } else if ("NTEXT".equals(typeName)) { column.setType(Types.CLOB); } } } catch (SQLException e) { log.error("Error getting columns", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.error("Error closing result set", e); } } try { stmt.close(); } catch (SQLException e) { log.error("Error closing statement", e); } } return (Column[]) columnList.toArray(new Column[columnList.size()]); }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the java type for the given SQL type from {@link Types}. *///from ww w . j a va 2s . c om public static Class<?> getJavaType(int type, int size, int decimals) { switch (type) { case Types.CHAR: if (size == 1) return char.class; // no break case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: return String.class; case Types.BIT: return boolean.class; case Types.TINYINT: return byte.class; case Types.SMALLINT: return short.class; case Types.INTEGER: return int.class; case Types.BIGINT: return long.class; case Types.REAL: case Types.FLOAT: return float.class; case Types.DOUBLE: case Types.NUMERIC: return double.class; case Types.DECIMAL: // oracle uses this for everything, so look at size and decimals if (decimals == 0 && size < 10) return int.class; else if (decimals == 0) return long.class; return double.class; // ### return a BigDecimal if the size if out of double range? case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Date.class; default: return Object.class; } }