Java Code Examples for org.springframework.jdbc.support.lob.LobCreator#setClobAsString()
The following examples show how to use
org.springframework.jdbc.support.lob.LobCreator#setClobAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClobStringType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected void nullSafeSetInternal( PreparedStatement ps, int index, Object value, LobCreator lobCreator) throws SQLException { lobCreator.setClobAsString(ps, index, (String) value); }
Example 2
Source File: ClobStringType.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void nullSafeSetInternal( PreparedStatement ps, int index, Object value, LobCreator lobCreator) throws SQLException { lobCreator.setClobAsString(ps, index, (String) value); }
Example 3
Source File: AltibaseClobStringTypeHandler.java From oslits with GNU General Public License v3.0 | 4 votes |
protected void setParameterInternal( PreparedStatement ps, int index, Object value, String jdbcType, LobCreator lobCreator) throws SQLException { lobCreator.setClobAsString(ps, index, (String) value); }
Example 4
Source File: RdbEventRecordLoader.java From DataLink with Apache License 2.0 | 4 votes |
@Override protected void fillPreparedStatement(PreparedStatement ps, LobCreator lobCreator, RdbEventRecord record, DbDialect dbDialect, TaskWriterContext context) throws SQLException { EventType type = record.getEventType(); // 注意insert/update语句对应的字段数序都是将主键排在后面 List<EventColumn> columns = new ArrayList<EventColumn>(); if (type.isInsert()) { columns.addAll(record.getColumns()); // insert为所有字段 columns.addAll(record.getKeys()); } else if (type.isDelete()) { columns.addAll(record.getKeys()); } else if (type.isUpdate()) { boolean existOldKeys = !CollectionUtils.isEmpty(record.getOldKeys()); boolean hasAutoIncrementNotKeyColumns = dbDialect.hasAutoIncrementNotKeyColumns(record.getSchemaName(), record.getTableName()); if (hasAutoIncrementNotKeyColumns) { columns.addAll(record.getUpdatedColumns());// 只更新带有isUpdate=true的字段 } else { columns.addAll(record.getColumns());// update、upsert都更新所有字段 } columns.addAll(record.getKeys()); if (existOldKeys) { columns.addAll(record.getOldKeys()); } } // 获取一下当前字段名的数据是否必填 boolean isSyncAutoAddColumn = context.getWriterParameter().isSyncAutoAddColumn(); Map<String, Boolean> isRequiredMap = buildRequiredMap(dbDialect, record, columns, isSyncAutoAddColumn); Table table = dbDialect.findTable(record.getSchemaName(), record.getTableName()); for (int i = 0; i < columns.size(); i++) { int paramIndex = i + 1; EventColumn column = columns.get(i); Boolean isRequired = isRequiredMap.get(StringUtils.lowerCase(column.getColumnName())); int sqlType = getSqlType(column, table, record); Object param = null; if (dbDialect instanceof MysqlDialect && (sqlType == Types.TIME || sqlType == Types.TIMESTAMP || sqlType == Types.DATE)) { // 解决mysql的0000-00-00 00:00:00问题,直接依赖mysql // driver进行处理,如果转化为Timestamp会出错 param = column.getColumnValue(); } else { param = SqlUtils.stringToSqlValue(column.getColumnValue(), sqlType, isRequired, dbDialect.isEmptyStringNulled()); } try { switch (sqlType) { case Types.CLOB: lobCreator.setClobAsString(ps, paramIndex, (String) param); break; case Types.BLOB: lobCreator.setBlobAsBytes(ps, paramIndex, param instanceof String ? ((String) param).getBytes() : (byte[]) param); break; case Types.TIME: case Types.TIMESTAMP: case Types.DATE: // 只处理mysql的时间类型,oracle的进行转化处理 if (dbDialect instanceof MysqlDialect) { // 解决mysql的0000-00-00 00:00:00问题,直接依赖mysql // driver进行处理,如果转化为Timestamp会出错 ps.setObject(paramIndex, param); } else { StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param); } break; case Types.BIT: // 只处理mysql的bit类型,bit最多存储64位,所以需要使用BigInteger进行处理才能不丢精度 // mysql driver将bit按照setInt进行处理,会导致数据越界 if (dbDialect instanceof MysqlDialect) { StatementCreatorUtils.setParameterValue(ps, paramIndex, Types.DECIMAL, null, param); } else if (dbDialect instanceof SqlServerDialect) { StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param.toString()); } else { StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param); } break; default: StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param); break; } } catch (SQLException ex) { logger.error("SetParam error , [mappingId={}, sqltype={}, value={}]", RecordMeta.mediaMapping(record).getId(), sqlType, param); throw ex; } } }