当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatementCreator.createPreparedStatement方法代码示例

本文整理汇总了Java中org.springframework.jdbc.core.PreparedStatementCreator.createPreparedStatement方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatementCreator.createPreparedStatement方法的具体用法?Java PreparedStatementCreator.createPreparedStatement怎么用?Java PreparedStatementCreator.createPreparedStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.jdbc.core.PreparedStatementCreator的用法示例。


在下文中一共展示了PreparedStatementCreator.createPreparedStatement方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: endingNoSpace

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void endingNoSpace() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  map.put("twenty", 20);
  String sql = "SELECT 1 FROM dual WHERE 1 = :ten or 20 = :twenty";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql, new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);

  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(oracleStatement).setObjectAtName("ten", 10);
  verify(oracleStatement).setObjectAtName("twenty", 20);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:22,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例2: setNullNoType

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void setNullNoType() throws SQLException {
  Map<String, Object> map = new HashMap<>(2);
  map.put("ten", 10);
  map.put("twenty", null);
  String sql = "SELECT 1 FROM dual WHERE 1 = :ten or 20 = :twenty";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql, new MapSqlParameterSource(map));
  
  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);
  
  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);
  
  preparedStatementCreator.createPreparedStatement(connection);
  
  verify(oracleStatement).setObjectAtName("ten", 10);
  verify(oracleStatement).setNullAtName("twenty", Types.NULL);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:22,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例3: setWithType

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void setWithType() throws SQLException {
  MapSqlParameterSource source = new MapSqlParameterSource(new HashMap<String, Object>(2));
  source.addValue("ten", 10, Types.NUMERIC);
  source.addValue("twenty", null, Types.VARCHAR);
  String sql = "SELECT 1 FROM dual WHERE 1 = :ten or 20 = :twenty";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql, source);
  
  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);
  
  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);
  
  preparedStatementCreator.createPreparedStatement(connection);
  
  verify(oracleStatement).setObjectAtName("ten", 10, Types.NUMERIC);
  verify(oracleStatement).setNullAtName("twenty", Types.VARCHAR);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:22,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例4: endingWithSpace

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void endingWithSpace() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  map.put("twenty", 20);
  String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 20 = :twenty ";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql, new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);

  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(oracleStatement).setObjectAtName("ten", 10);
  verify(oracleStatement).setObjectAtName("twenty", 20);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:22,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例5: repetition

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void repetition() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 0 < :ten ";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
    sql, new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);

  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(oracleStatement).setObjectAtName("ten", 10);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:20,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例6: commonPrefix

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
public void commonPrefix() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("arg", 10);
  map.put("arg2", 20);
  String sql = "SELECT 1 FROM dual WHERE 10 = :arg or 20 = :arg2";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql, new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);
  OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);

  when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
  when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(oracleStatement).setObjectAtName("arg", 10);
  verify(oracleStatement).setObjectAtName("arg2", 20);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:22,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例7: collection

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
@Ignore("unsupported")
public void collection() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  map.put("twenty", 20);
  map.put("collection", Arrays.asList(1, 23, 42));
  String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (:collection) or 20 = :twenty";
  String expectedSql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (?,?,?) or 20 = :twenty";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql,
      new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);

  when(connection.prepareStatement(expectedSql)).thenReturn(preparedStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(preparedStatement).setObject(1, 10);
  verify(preparedStatement).setObject(2, 1);
  verify(preparedStatement).setObject(3, 23);
  verify(preparedStatement).setObject(4, 42);
  verify(preparedStatement).setObject(5, 20);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:27,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例8: endsWithCollection

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
@Ignore("unsupported")
public void endsWithCollection() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  map.put("twenty", 20);
  map.put("collection", Arrays.asList(1, 23, 42));
  String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (:collection)";
  String expectedSql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (?,?,?)";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql,
      new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);

  when(connection.prepareStatement(expectedSql)).thenReturn(preparedStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(preparedStatement).setObject(1, 10);
  verify(preparedStatement).setObject(2, 1);
  verify(preparedStatement).setObject(3, 23);
  verify(preparedStatement).setObject(4, 42);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:26,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例9: endsWithCollectionSpace

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Test
@Ignore("unsupported")
public void endsWithCollectionSpace() throws SQLException {
  Map<String, Object> map = new HashMap<>(3);
  map.put("ten", 10);
  map.put("twenty", 20);
  map.put("collection", Arrays.asList(1, 23, 42));
  String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (:collection) ";
  String expectedSql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (?,?,?) ";
  PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(
      sql,
      new MapSqlParameterSource(map));

  Connection connection = mock(Connection.class);
  PreparedStatement preparedStatement = mock(PreparedStatement.class);

  when(connection.prepareStatement(expectedSql)).thenReturn(preparedStatement);

  preparedStatementCreator.createPreparedStatement(connection);

  verify(preparedStatement).setObject(1, 10);
  verify(preparedStatement).setObject(2, 1);
  verify(preparedStatement).setObject(3, 23);
  verify(preparedStatement).setObject(4, 42);
}
 
开发者ID:ferstl,项目名称:spring-jdbc-oracle,代码行数:26,代码来源:OracleNamedParameterJdbcTemplateTest.java

示例10: processStreamList

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
protected void processStreamList(Exchange exchange, PreparedStatementCreator statementCreator, String preparedQuery) throws Exception {
    log.trace("processStreamList: {}", preparedQuery);

    // do not use the jdbcTemplate as it will auto-close connection/ps/rs when exiting the execute method
    // and we need to keep the connection alive while routing and close it when the Exchange is done being routed
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        con = dataSource.getConnection();
        ps = statementCreator.createPreparedStatement(con);

        boolean isResultSet = ps.execute();
        if (isResultSet) {
            rs = ps.getResultSet();
            ResultSetIterator iterator = getEndpoint().queryForStreamList(con, ps, rs);
            if (getEndpoint().isNoop()) {
                exchange.getOut().setBody(exchange.getIn().getBody());
            } else if (getEndpoint().getOutputHeader() != null) {
                exchange.getOut().setBody(exchange.getIn().getBody());
                exchange.getOut().setHeader(getEndpoint().getOutputHeader(), iterator);
            } else {
                exchange.getOut().setBody(iterator);
            }
            // we do not know the row count so we cannot set a ROW_COUNT header
            // defer closing the iterator when the exchange is complete
            exchange.addOnCompletion(new ResultSetIteratorCompletion(iterator));
        }
    } catch (Exception e) {
        // in case of exception then close all this before rethrow
        closeConnection(con);
        closeStatement(ps);
        closeResultSet(rs);
        throw e;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:ElsqlProducer.java

示例11: openCursor

import org.springframework.jdbc.core.PreparedStatementCreator; //导入方法依赖的package包/类
@Override
	protected void openCursor(Connection con) {
		
		//MyParsedSqlDel parsedSql = getParsedSql(sql);
		
		//String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql.getDelegate(), paramSource);
		
		//String theSql = sqlToUse;
		
		
		try {
//			if (isUseSharedExtendedConnection()) {
//				preparedStatement = con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
//						ResultSet.HOLD_CURSORS_OVER_COMMIT);
//			}
//			else {
//				preparedStatement = con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
//			}
//			applyStatementSettings(preparedStatement);
//			if (this.preparedStatementSetter != null) {
//				
//				
//				preparedStatementSetter.setValues(preparedStatement);
//				
//				
//				
//				
//				
//			}
//			this.rs = preparedStatement.executeQuery();
			
			ParsedSql parsedSql1 = this.getParsedSql(sql).getDelegate();
			String sqlToUse1 = NamedParameterUtils.substituteNamedParameters(parsedSql1, paramSource);
			Object[] params = NamedParameterUtils.buildValueArray(parsedSql1, paramSource, null);
			List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql1, paramSource);
			PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse1, declaredParameters);
			pscf.setResultSetType( ResultSet.TYPE_FORWARD_ONLY );
			pscf.setUpdatableResults(false);
			PreparedStatementCreator preparedStatementCreator = pscf.newPreparedStatementCreator(params);
			
			//con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
			
			preparedStatement = preparedStatementCreator.createPreparedStatement(con);
			this.rs = preparedStatement.executeQuery();
			
			handleWarnings(preparedStatement);
		}
		catch (SQLException se) {
			close();
			throw getExceptionTranslator().translate("Executing query", getSql(), se);
		}

	}
 
开发者ID:danidemi,项目名称:jlubricant,代码行数:54,代码来源:NamedJdbcCursorItemReader.java


注:本文中的org.springframework.jdbc.core.PreparedStatementCreator.createPreparedStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。