本文整理汇总了Java中java.sql.PreparedStatement.setURL方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setURL方法的具体用法?Java PreparedStatement.setURL怎么用?Java PreparedStatement.setURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setURL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyParameterMapToPreparedStatement
import java.sql.PreparedStatement; //导入方法依赖的package包/类
private PreparedStatement applyParameterMapToPreparedStatement(
PreparedStatement preparedStatement,
Map<String, Object> parameterMap,
List<String> parametersInSqlSorted) {
try {
for (int i = 0; i < parametersInSqlSorted.size(); i++) {
Object value = parameterMap.get(parametersInSqlSorted.get(i));
int positionInPreparedStatement = i + 1; // jdbc parameters start with 1...
if (value instanceof BigDecimal) {
preparedStatement.setBigDecimal(positionInPreparedStatement, (BigDecimal) value);
} else if (value instanceof Boolean) {
preparedStatement.setBoolean(positionInPreparedStatement, (Boolean) value);
} else if (value instanceof Date) {
preparedStatement.setDate(positionInPreparedStatement, (Date) value);
} else if (value instanceof Double) {
preparedStatement.setDouble(positionInPreparedStatement, (Double) value);
} else if (value instanceof Float) {
preparedStatement.setFloat(positionInPreparedStatement, (Float) value);
} else if (value instanceof Integer) {
preparedStatement.setInt(positionInPreparedStatement, (Integer) value);
} else if (value instanceof Long) {
preparedStatement.setLong(positionInPreparedStatement, (Long) value);
} else if (value instanceof Short) {
preparedStatement.setShort(positionInPreparedStatement, (Short) value);
} else if (value instanceof String) {
preparedStatement.setString(positionInPreparedStatement, (String) value);
} else if (value instanceof Time) {
preparedStatement.setTime(positionInPreparedStatement, (Time) value);
} else if (value instanceof Timestamp) {
preparedStatement.setTimestamp(positionInPreparedStatement, (Timestamp) value);
} else if (value instanceof URL) {
preparedStatement.setURL(positionInPreparedStatement, (URL) value);
} else {
// Kind of a fallback. If you expect some other behavior feel
// free to implement it.
preparedStatement.setObject(positionInPreparedStatement, value);
}
}
} catch (SQLException ex) {
throw new SqlifyException("Ops. An error occurred.", ex);
}
return preparedStatement;
}