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


Java PreparedStatementCallback类代码示例

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


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

示例1: deleteFile

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
public Boolean deleteFile(final String filename, final String key)
		throws FileNotFoundException, IOException {
	String cloudfilesql = "delete CLOUDFILEDATA where FILENAME=?";

	return jdbcTemplate.execute(cloudfilesql,
			new PreparedStatementCallback<Boolean>() {

				@Override
				public Boolean doInPreparedStatement(PreparedStatement ps)
						throws SQLException, DataAccessException {
					ps.setString(1, filename.trim());
					return ps.execute();
				}

			});
}
 
开发者ID:cyberheartmi9,项目名称:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代码行数:17,代码来源:RegistrationDAO.java

示例2: testExecute

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Test
public void testExecute() throws SQLException {
	given(preparedStatement.executeUpdate()).willReturn(1);

	params.put("perfId", 1);
	params.put("priceId", 1);
	Object result = namedParameterTemplate.execute(UPDATE_NAMED_PARAMETERS, params,
			new PreparedStatementCallback<Object>() {
				@Override
				public Object doInPreparedStatement(PreparedStatement ps)
						throws SQLException {
					assertEquals(preparedStatement, ps);
					ps.executeUpdate();
					return "result";
				}
			});

	assertEquals("result", result);
	verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
	verify(preparedStatement).setObject(1, 1);
	verify(preparedStatement).setObject(2, 1);
	verify(preparedStatement).close();
	verify(connection).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:NamedParameterJdbcTemplateTests.java

示例3: testExecuteWithTypedParameters

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@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 {
					assertEquals(preparedStatement, ps);
					ps.executeUpdate();
					return "result";
				}
			});

	assertEquals("result", result);
	verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
	verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
	verify(preparedStatement).setObject(2, 1, Types.INTEGER);
	verify(preparedStatement).close();
	verify(connection).close();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:NamedParameterJdbcTemplateTests.java

示例4: deleteFromBlob

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
/**
 * 从删除一条代表二进制数据的记录
 * 
 * @param id
 *            主键
 * @throws SQLException
 */
protected void deleteFromBlob(final String id) throws SQLException {
	final String sql = "DELETE FROM BDF2_BLOB_STORE WHERE ID_=?";
	int updatedRowCount = super.getJdbcTemplate().execute(sql,
			new PreparedStatementCallback<Integer>() {
				public Integer doInPreparedStatement(
						PreparedStatement preparedstatement)
						throws SQLException, DataAccessException {
					preparedstatement.setString(1, id);
					return preparedstatement.executeUpdate();
				}
			});
	if (0 == updatedRowCount) {
		throw new SQLException(String.format("未能成功删除大二进制对象[id=%s],请检查其是否存在", id));
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:23,代码来源:LobStoreServiceImpl.java

示例5: deleteFromClob

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
/**
 * 删除一条代表文本的记录。
 * 
 * @param id
 *            主键
 * @throws SQLException
 */
protected void deleteFromClob(final String id) throws SQLException {
	final String sql = "DELETE FROM BDF2_CLOB_STORE WHERE ID_=?";
	int updatedRowCount = super.getJdbcTemplate().execute(sql,
			new PreparedStatementCallback<Integer>() {
				public Integer doInPreparedStatement(
						PreparedStatement preparedstatement)
						throws SQLException, DataAccessException {
					preparedstatement.setString(1, id);
					return preparedstatement.executeUpdate();
				}

			});
	if (0 == updatedRowCount) {
		throw new SQLException(String.format("未能成功删除大字符对象[id=%s],请检查其是否存在",
				id));
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:25,代码来源:LobStoreServiceImpl.java

示例6: getAppCategoryRank

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public List<App> getAppCategoryRank(final int parentId, final int subCatalog, final int top) {
    PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
        @Override
        public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, parentId);
            ps.setInt(2, subCatalog);
            ps.setInt(3, top);
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.last()) {
                    int count = rs.getRow();
                    List<App> list = new ArrayList<App>(count);
                    rs.beforeFirst();
                    App app = null;
                    while (rs.next()) {
                        app = appRowMapper.mapRow(rs, rs.getRow());
                        changeOutputImpl.setUrls(app);
                        list.add(app);
                    }
                    return list;
                }

            } catch (Exception e) {
                logger.error("SQL data error:", e);
                return null;
            } finally {
                if (null != rs)
                    rs.close();
            }
            return null;
        }
    };
    return jdbcTemplate.execute(QUERY_APP_CATEGORY_TOP_SQL, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:AppRankDaoImpl.java

示例7: getAppDefultRank

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public List<App> getAppDefultRank(final int typeId, final int top) {
    PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
        @Override
        public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, typeId);
            ps.setInt(2, top);
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.last()) {
                    int count = rs.getRow();
                    List<App> list = new ArrayList<App>(count);
                    rs.beforeFirst();
                    App app = null;
                    while (rs.next()) {
                        app = appRowMapper.mapRow(rs, rs.getRow());
                        changeOutputImpl.setUrls(app);
                        list.add(app);
                    }
                    return list;
                }

            } catch (Exception e) {
                logger.error("SQL data error:", e);
                return null;
            } finally {
                if (null != rs)
                    rs.close();
            }
            return null;
        }
    };
    return jdbcTemplate.execute(QUERY_APP_DEFAULT_TOP_SQL, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:36,代码来源:AppRankDaoImpl.java

示例8: getAppTypes

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public List<AppType> getAppTypes(final int parentId) {
    PreparedStatementCallback<List<AppType>> cb = new PreparedStatementCallback<List<AppType>>() {
        @Override
        public List<AppType> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ResultSet rs = null;
            try {
                ps.setInt(1, parentId);
                ps.setInt(2, parentId);
                rs = ps.executeQuery();
                // predicate count.
                if (rs.last()) {
                    int count = rs.getRow();
                    List<AppType> list = new ArrayList<AppType>(count);
                    rs.beforeFirst();
                    AppType appType = null;
                    while (rs.next()) {
                        appType = appTypeRowMapper.mapRow(rs, rs.getRow());
                        list.add(appType);
                    }
                    return list;
                } else {
                    return null;
                }
            } finally {
                if (null != rs) {
                    rs.close();
                }
            }
        }
    };
    return this.jdbcTemplate.execute(appTypes, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:34,代码来源:AppsDaoImpl.java

示例9: getPowerTuiJianTopic

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public Topic getPowerTuiJianTopic(final int topicid) {
    PreparedStatementCallback<Topic> cb = new PreparedStatementCallback<Topic>() {
        @Override
        public Topic doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ResultSet rs = null;
            try {
                ps.setInt(1, topicid);
                rs = ps.executeQuery();
                if (!rs.next()) {
                    return null;
                }
                Topic topic = topicRowMapper.mapRow(rs, 1);
                changeOutputImpl.setUrls(topic);
                return topic;
            } finally {
                if (null != rs)
                    rs.close();
            }
        }
    };
    return jdbcTemplate.execute(topicPowerTuiJian, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:24,代码来源:AppsDaoImpl.java

示例10: getPowerChannelTuiJianTopic

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public Topic getPowerChannelTuiJianTopic(final int topicid) {
    PreparedStatementCallback<Topic> cb = new PreparedStatementCallback<Topic>() {
        @Override
        public Topic doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ResultSet rs = null;
            try {
                ps.setInt(1, topicid);
                rs = ps.executeQuery();
                if (!rs.next()) {
                    return null;
                }
                Topic topic = topicRowMapper.mapRow(rs, 1);
                changeOutputImpl.setUrls(topic);
                return topic;
            } finally {
                if (null != rs)
                    rs.close();
            }
        }
    };
    return jdbcTemplate.execute(topicPowerChannelTuiJian, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:24,代码来源:AppsDaoImpl.java

示例11: testExecuteNoParameters

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Test
public void testExecuteNoParameters() throws SQLException {
	given(preparedStatement.executeUpdate()).willReturn(1);

	Object result = namedParameterTemplate.execute(SELECT_NO_PARAMETERS,
			new PreparedStatementCallback<Object>() {
				@Override
				public Object doInPreparedStatement(PreparedStatement ps)
						throws SQLException {
					assertEquals(preparedStatement, ps);
					ps.executeQuery();
					return "result";
				}
			});

	assertEquals("result", result);
	verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
	verify(preparedStatement).close();
	verify(connection).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:NamedParameterJdbcTemplateTests.java

示例12: ack

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
public Position ack(final List<Record> records) throws YuGongException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getSourceDs());
    jdbcTemplate.execute(mlogCleanSql, new PreparedStatementCallback() {

        @Override
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            for (Record record : records) {
                OracleIncrementRecord incRecord = (OracleIncrementRecord) record;
                ps.setObject(1, incRecord.getRowId().getValue(), incRecord.getRowId().getColumn().getType());
                ps.addBatch();
            }

            ps.executeBatch();
            return null;
        }
    });

    return null;
}
 
开发者ID:alibaba,项目名称:yugong,代码行数:20,代码来源:OracleMaterializedIncRecordExtractor.java

示例13: getMLogTableName

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
/**
 * <pre>
 * 常见的物化视图创建语句:
 * 1. CREATE MATERIALIZED VIEW LOG ON test_all_target with primary key; 
 * 
 * 本方法,主要提取生成物化视图的表名
 * </pre>
 * 
 * @param dataSource
 * @param schemaName
 * @param tableName
 * @return
 */
public static String getMLogTableName(final DataSource dataSource, final String schemaName, final String tableName) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = StringUtils.isNotEmpty(schemaName) ? mlogSchemaQuerySql : mlogQuerySql;
    return (String) jdbcTemplate.execute(sql, new PreparedStatementCallback() {

        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            DatabaseMetaData metaData = ps.getConnection().getMetaData();
            String sName = getIdentifierName(schemaName, metaData);
            String tName = getIdentifierName(tableName, metaData);
            ps.setString(1, tName);
            if (StringUtils.isNotEmpty(schemaName)) {
                ps.setString(2, sName);
            }
            ResultSet rs = ps.executeQuery();
            String log = null;
            if (rs.next()) {
                log = rs.getString("log_table");
            }

            rs.close();
            return log;
        }
    });
}
 
开发者ID:alibaba,项目名称:yugong,代码行数:38,代码来源:TableMetaGenerator.java

示例14: clearMlog

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
@Override
public void clearMlog(final List<ColumnValue> records, String mlogCleanSql) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getSourceDs());
    jdbcTemplate.execute(mlogCleanSql, new PreparedStatementCallback() {

        @Override
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            for (ColumnValue record : records) {
                ps.setObject(1, record.getValue(), record.getColumn().getType());
                ps.addBatch();
            }
            ps.executeBatch();
            return null;
        }
    });
}
 
开发者ID:kevinKaiF,项目名称:cango,代码行数:17,代码来源:KafkaIncRecordExtractor.java

示例15: getSingleMlogRecord

import org.springframework.jdbc.core.PreparedStatementCallback; //导入依赖的package包/类
/**
 * 根据mlog物化日志表的SEQUENCE$$字段单独查询
 *
 * @param sequence
 * @param context
 * @param columns
 * @return
 */
private List<ColumnValue> getSingleMlogRecord(final String singleMlogExtractSql, final int sequence, final YuGongContext context, final List<ColumnMeta> mlogCols, final List<ColumnMeta> columns, final List<ColumnValue> rowIds) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getSourceDs());
    final List<ColumnValue> columnValues = new ArrayList<ColumnValue>();
    return (List<ColumnValue>) jdbcTemplate.execute(singleMlogExtractSql, new PreparedStatementCallback() {
        @Override
        public List<ColumnValue> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, sequence);
            ResultSet rs = ps.executeQuery();
            try {
                while (rs.next()) {
                    rowIds.add(new ColumnValue(rowidColumn, rs.getObject("rowid")));
                    columnValues.addAll(buildColumnValue(rs, context.getSourceEncoding(), mlogCols, columns));
                }
            } finally {
                JdbcUtils.closeResultSet(rs);
            }
            return columnValues;
        }
    });
}
 
开发者ID:kevinKaiF,项目名称:cango,代码行数:29,代码来源:KafkaIncRecordExtractor.java


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