本文整理汇总了Java中org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue方法的典型用法代码示例。如果您正苦于以下问题:Java StatementCreatorUtils.setParameterValue方法的具体用法?Java StatementCreatorUtils.setParameterValue怎么用?Java StatementCreatorUtils.setParameterValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.core.StatementCreatorUtils
的用法示例。
在下文中一共展示了StatementCreatorUtils.setParameterValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCursorForJoin
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@Override
public String getCursorForJoin(List<String> tables, List<String> columnNames, String from,
String where, List<String> order, Boolean ascending, int limit) {
List<? super Object> args = new ArrayList<>();
where = convertToPreparedStatement(where, args);
String sql = sqlGenerator.constructSelectJoin(tables, columnNames, from, where, order, ascending, limit);
try {
PreparedStatement pstmt = getPreparedStatementForCursor(sql);
for (int i = 0; i < args.size(); i++) {
StatementCreatorUtils.setParameterValue(pstmt, i + 1, SqlTypeValue.TYPE_UNKNOWN, args.get(i));
}
ResultSet rs = pstmt.executeQuery();
String uuid = IDGenerator.getUUID();
cache.putCursor(uuid, rs);
return uuid;
} catch (SQLException e) {
throw RaptureExceptionFactory.create(String.format("Sql Exception executing cursor for joined query [%s]", e.getMessage()));
}
}
示例2: setParameterValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
/**
* Internal implementation for setting parameter values
* @param preparedStatement the PreparedStatement
* @param values the values to be set
*/
private void setParameterValues(PreparedStatement preparedStatement, List<Object> values, int[] columnTypes)
throws SQLException {
int colIndex = 0;
for (Object value : values) {
colIndex++;
if (columnTypes == null || colIndex > columnTypes.length) {
StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
}
else {
StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
}
}
}
示例3: doPreparedStatement
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes,
final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue,
sqlType,
SqlUtils.isTextType(sqlType),
dbDialect.isEmptyStringNulled());
switch (sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
case Types.TIME:
case Types.TIMESTAMP:
case Types.DATE:
ps.setObject(paramIndex, sqlValue);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
示例4: doPreparedStatement
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes,
final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue,
sqlType,
SqlUtils.isTextType(sqlType),
dbDialect.isEmptyStringNulled());
switch (sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
示例5: doPreparedStatement
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes,
final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue, sqlType, SqlUtils.isTextType(sqlType),
dbDialect.isEmptyStringNulled());
switch (sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
示例6: setParameterValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
/**
* Internal implementation for setting parameter values
* @param preparedStatement the PreparedStatement
* @param values the values to be set
*/
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, int... columnTypes)
throws SQLException {
int colIndex = 0;
for (Object value : values) {
colIndex++;
if (columnTypes == null || colIndex > columnTypes.length) {
StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
}
else {
StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
}
}
}
示例7: setParameters
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void setParameters(PreparedStatement ps) throws SQLException {
try {
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings != null) {
int paramMappingSize = parameterMappings.size();
for (int i = 0; i < paramMappingSize; i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = "";
} else {
Class<?> type = parameterObject.getClass();
boolean isPrimitive = isColumnType(type);
if (isPrimitive) {
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
}
}
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, value);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new SQLException(e.getMessage(), e);
}
}
示例8: addParameter
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
public void addParameter(CallableStatement callableStatement, Map batchRow) throws SQLException {
int i = 1;
for (SqlParameter parameter : getSqlParameterList()) {
StatementCreatorUtils.setParameterValue(callableStatement, i, parameter, batchRow.get(parameter.getName()));
i++;
}
}
示例9: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@Override
public void setValues(String[] item, PreparedStatement ps) throws SQLException {
Assert.isInstanceOf(String[].class, item, "Input to map PreparedStatement parameters must be of type String[].");
System.out.println(String.join(",", item));
for(int i=0; i<item.length; i++ ){
StatementCreatorUtils.setParameterValue(ps, i+1, SqlTypeValue.TYPE_UNKNOWN, item[i]);
}
}
示例10: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
public static int setValues(PreparedStatement ps, Object[] args, int startIndex) throws SQLException {
int j = startIndex;
if (args != null) {
for (int i = 0; i < args.length; i++, j++) {
Object arg = args[i];
if (arg instanceof SqlParameterValue) {
SqlParameterValue paramValue = (SqlParameterValue) arg;
StatementCreatorUtils.setParameterValue(ps, j, paramValue, paramValue.getValue());
} else {
StatementCreatorUtils.setParameterValue(ps, j, Types.OTHER, arg);
}
}
}
return j;
}
示例11: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@Override
public synchronized void setValues(PreparedStatement sPs) throws SQLException {
try {
String aResolvedValue;
for(int i = 0; i < lookupFieldsExpressions.length; i++) {
aResolvedValue = getExpressionResolver().evaluate(lookupFieldsExpressions[i], getEvaluationContext(), String.class);
StatementCreatorUtils.setParameterValue(sPs, i + 1, SqlTypeValue.TYPE_UNKNOWN, aResolvedValue);
}
} catch (Exception e) {
throw new SQLException(new PreparedStatementCreationException(e));
}
}
示例12: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] params = batchParams[i];
int colIndex = 0;
for (Object param : params) {
colIndex++;
StatementCreatorUtils.setParameterValue(ps, colIndex, SqlTypeValue.TYPE_UNKNOWN,
Jsr310JdbcUtils.convertIfNecessary(param, zoneId));
}
}
示例13: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object param = batchParams[i];
StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN,
Jsr310JdbcUtils.convertIfNecessary(param, zoneId));
}
示例14: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
public void setValues(PreparedStatement ps) throws SQLException {
int argIndx = 1;
if (this.args != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
Collection entries = (Collection) arg;
for (Iterator it = entries.iterator(); it.hasNext();) {
Object entry = it.next();
if (entry instanceof Object[]) {
Object[] valueArray = ((Object[])entry);
for (int k = 0; k < valueArray.length; k++) {
Object argValue = valueArray[k];
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue);
}
}
else {
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry);
}
}
}
else {
if(this.argTypes[i] == Types.BLOB) {
byte[] bytes = (byte[])this.args[i];
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ps.setBinaryStream(argIndx++, bais, bytes.length);
} else {
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], arg);
}
}
}
}
}
示例15: setValues
import org.springframework.jdbc.core.StatementCreatorUtils; //导入方法依赖的package包/类
public void setValues(PreparedStatement ps) throws SQLException {
int argIndx = 1;
if (this.args != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
Collection entries = (Collection) arg;
for (Iterator it = entries.iterator(); it.hasNext();) {
Object entry = it.next();
if (entry instanceof Object[]) {
Object[] valueArray = ((Object[])entry);
for (int k = 0; k < valueArray.length; k++) {
Object argValue = valueArray[k];
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue);
}
}
else {
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry);
}
}
}
else {
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], arg);
}
}
}
}