Package org.springframework.jdbc.core

Examples of org.springframework.jdbc.core.SqlParameterValue


   */
  public static Object getTypedValue(SqlParameterSource source, String parameterName) {
    int sqlType = source.getSqlType(parameterName);
    if (sqlType != SqlParameterSource.TYPE_UNKNOWN) {
      if (source.getTypeName(parameterName) != null) {
        return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName));
      }
      else {
        return new SqlParameterValue(sqlType, source.getValue(parameterName));
      }
    }
    else {
      return source.getValue(parameterName);
    }
View Full Code Here


  @Test
  public void testExecuteWithTypedParameters() throws SQLException {
    given(preparedStatement.executeUpdate()).willReturn(1);

    params.put("perfId", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("priceId", new SqlParameterValue(Types.INTEGER, 1));
    Object result = namedParameterTemplate.execute(UPDATE_NAMED_PARAMETERS, params,
        new PreparedStatementCallback<Object>() {
          @Override
          public Object doInPreparedStatement(PreparedStatement ps)
              throws SQLException {
View Full Code Here

  public void testQueryWithResultSetExtractor() throws SQLException {
    given(resultSet.next()).willReturn(true);
    given(resultSet.getInt("id")).willReturn(1);
    given(resultSet.getString("forename")).willReturn("rod");

    params.put("id", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("country", "UK");
    Customer cust = namedParameterTemplate.query(SELECT_NAMED_PARAMETERS, params,
        new ResultSetExtractor<Customer>() {
          @Override
          public Customer extractData(ResultSet rs) throws SQLException,
View Full Code Here

  public void testQueryWithRowCallbackHandler() throws SQLException {
    given(resultSet.next()).willReturn(true, false);
    given(resultSet.getInt("id")).willReturn(1);
    given(resultSet.getString("forename")).willReturn("rod");

    params.put("id", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("country", "UK");
    final List<Customer> customers = new LinkedList<Customer>();
    namedParameterTemplate.query(SELECT_NAMED_PARAMETERS, params, new RowCallbackHandler() {
      @Override
      public void processRow(ResultSet rs) throws SQLException {
View Full Code Here

  public void testQueryWithRowMapper() throws SQLException {
    given(resultSet.next()).willReturn(true, false);
    given(resultSet.getInt("id")).willReturn(1);
    given(resultSet.getString("forename")).willReturn("rod");

    params.put("id", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("country", "UK");
    List<Customer> customers = namedParameterTemplate.query(SELECT_NAMED_PARAMETERS, params,
        new RowMapper<Customer>() {
          @Override
          public Customer mapRow(ResultSet rs, int rownum) throws SQLException {
View Full Code Here

  public void testQueryForObjectWithRowMapper() throws SQLException {
    given(resultSet.next()).willReturn(true, false);
    given(resultSet.getInt("id")).willReturn(1);
    given(resultSet.getString("forename")).willReturn("rod");

    params.put("id", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("country", "UK");
    Customer cust = namedParameterTemplate.queryForObject(SELECT_NAMED_PARAMETERS, params,
        new RowMapper<Customer>() {
          @Override
          public Customer mapRow(ResultSet rs, int rownum) throws SQLException {
View Full Code Here

  @Test
  public void testUpdateWithTypedParameters() throws SQLException {
    given(preparedStatement.executeUpdate()).willReturn(1);

    params.put("perfId", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("priceId", new SqlParameterValue(Types.INTEGER, 1));
    int rowsAffected = namedParameterTemplate.update(UPDATE_NAMED_PARAMETERS, params);

    assertEquals(1, rowsAffected);
    verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
    verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
View Full Code Here

   */
  public static Object getTypedValue(SqlParameterSource source, String parameterName) {
    int sqlType = source.getSqlType(parameterName);
    if (sqlType != SqlParameterSource.TYPE_UNKNOWN) {
      if (source.getTypeName(parameterName) != null) {
        return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName));
      }
      else {
        return new SqlParameterValue(sqlType, source.getValue(parameterName));
      }
    }
    else {
      return source.getValue(parameterName);
    }
View Full Code Here

  public MapSqlParameterSource addValues(Map<String, ?> values) {
    if (values != null) {
      for (Map.Entry<String, ?> entry : values.entrySet()) {
        this.values.put(entry.getKey(), entry.getValue());
        if (entry.getValue() instanceof SqlParameterValue) {
          SqlParameterValue value = (SqlParameterValue) entry.getValue();
          registerSqlType(entry.getKey(), value.getSqlType());
        }
      }
    }
    return this;
  }
View Full Code Here

    for (int i = 0; i < paramNames.size(); i++) {
      String paramName = paramNames.get(i);
      try {
        Object value = paramSource.getValue(paramName);
        SqlParameter param = findParameter(declaredParams, paramName, i);
        paramArray[i] = (param != null ? new SqlParameterValue(param, value) : value);
      }
      catch (IllegalArgumentException ex) {
        throw new InvalidDataAccessApiUsageException(
            "No value supplied for the SQL parameter '" + paramName + "': " + ex.getMessage());
      }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.SqlParameterValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.