jdbctemplate

How to set fetchSize for concrete query?

你。 提交于 2019-12-11 04:25:21
问题 I want to set fetchSize only for one query and I can't find appropriate api for that. my code looks like this: jdbcTemplate.query(query, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException {...} ); How can I pass fetchSize to the query ? 回答1: This can be done using PreparedStatementSetter (JavaDoc) Given the query select * from mytable where user_id > ? You can use jdbcTemplate.query(query, new PreparedStatementSetter() { @Override public void

MapSqlParameterSource Does Not Map Properly with NamedParameterJdbcTemplate for a stored procedure

十年热恋 提交于 2019-12-11 03:29:57
问题 I am trying to call a stored procedure using mapped parameters with NamedParameterJdbcTemplate (Spring 3.0), but for some strange reason certain values do not get passed to the stored procedure (Oracle 11.2)! The interface of the stored procedure in question: PROCEDURE my_stored_proc( h_id IN NUMBER, h_type IN VARCHAR2, h_status in varchar2 DEFAULT null, h_end_date IN DATE DEFAULT null, h_reason IN VARCHAR2 DEFAULT null, h_rating IN VARCHAR2 DEFAULT null, h_position IN VARCHAR2 DEFAULT null,

jdbc和jdbctemplate

跟風遠走 提交于 2019-12-10 20:15:43
这里是修真院后端小课堂,每篇分享文从 【背景介绍】【知识剖析】【常见问题】【解决方案】【编码实战】【扩展思考】【更多讨论】【参考文献】 八个方面深度解析后端知识/技能。 大家好,我是IT修真院武汉分院的王志雄,一枚正直纯洁善良的java程序员, 今天给大家分享一下,修真院官网java任务一,深度思考中的知识点: jdbc和jdbctemplate 背景介绍 jdbc是什么? JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API, 可以为多种关系数据库提供统一访问,它由一组用 Java语言 编写的类和接口组成。JDBC提供了 一种基准,据此可以构建更高级的工具和接口,使数据库开发人员能够编写数据库应用程序, 同时,JDBC也是个商标名。 它可以做什么 1,与数据库建立连接 2.发送造作数据库语句 3处理结果 jdbctemplate是什么 jdbc已经能够满足大部分用户最基本的对数据库的需求,但是在使用jdbc时,应用必须自己来管理数 据库资源.spring对数据库操作需求提供了,很好的支持,并在原始jdbc的基础上,构建了一个抽象层, 提供了许多shiyongjdbc的模板和驱动模块,为spring应用操作关系型数据库提供了更大的便利 知识剖析 一、 JDBC常用接口   Driver接口     -

Spring + JdbcTemplate + JdbcDaoSupport

梦想与她 提交于 2019-12-10 17:49:50
首先,数据库是这样的,很简单。 当然,要引入spring的包,这里我全部导入了,省事。 applicationContext.xml是这样的: [html] view plain copy < span> xml version = "1.0" encoding = "UTF-8" ?< < span> beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" < < span> bean id = "test" class = "jdbc.Test" < < span> property name = "dataSource" ref = "dataSource" < </> property < </> bean < < span> bean id = "dataSource" class = "org.springframework.jdbc

Error Inserting Java Character object value into Oracle CHAR(1) column

陌路散爱 提交于 2019-12-10 17:25:53
问题 I'm using a Spring jdbcTemplate.update(String sql, Object[] args) to execute a prepared insert statement on an Oracle database. One of the objects is a Character object containing the value 'Y', and the target column is of CHAR(1) type, but I'm receiving a java.sql.SQLException: Invalid column type exception. I've debugged this backwards and forwards and there is no doubt that it is this one particular object that is causing the problem. The insert executes as expected when this Character

spring--(22)JdbcTemplate

北战南征 提交于 2019-12-10 16:53:44
###1.导入jar包,必须jar包:c3p0、mysql-connector、beans、context、dao、jdbc,截图如下 ###2.db.properties jdbc.user=root jdbc.password=123456 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbcUrl=jdbc:mysql:///test?useUnicode=true&characterEncoding=UTF8 jdbc.initPoolSize=10 jdbc.maxPoolSize=50 ###3.applicationContext.xml <context:property-placeholder location="classpath:db.properties"/> <bean id="dataSources" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> <property name="driverClass" value="$

Spring jdbc 'select for update'

放肆的年华 提交于 2019-12-10 16:39:41
问题 I have the following method that I use with Spring JDBC public String getState() { String stateLink = template.queryForObject( "select state_url from state_scrape_queue where in_use = false ORDER BY scrape_timestamp NULLS FIRST LIMIT 1", (result, rowNum) -> { return result.getString("state_url"); }); return stateLink; } I can't find an example of how to do a for update with Spring JDBC. I want in_use to be set to true using for update. I need to use select for update since this application

Escaping a single quote when using JdbcTemplate

这一生的挚爱 提交于 2019-12-10 14:29:57
问题 We're using JdbcTemplate to modify our underlying Oracle database. We're doing this by way of the update(String sql) method. The code looks somehow like the following: String name = "My name's yellow"; String sql = "update FIELD set NAME = '" + name "' where ID = 10 jdbcTemplate.update(sql); This causes the error: java.sql.SQLException: ORA-00933: SQL command not properly ended The problem is the unescaped ' in the name variable. What's the most convenient and correct way to escape this

Retrieving Native Connection from JBOSS wrapped Connection

我只是一个虾纸丫 提交于 2019-12-10 13:15:44
问题 I need to pass an array Object to Oracle 11 DB. I am using annotations based Spring 3.1 and using SimpleJdbcCall to call the procedure on JBOSS server. Here is the relevant jdbcCall . SimpleJdbcCall call = new SimpleJdbcCall(dataSource) .withoutProcedureColumnMetaDataAccess() .withProcedureName(IbeginDataBaseConstants.PROCEDURE_CREATE_NEW_ADMIN.VAL) .declareParameters(new SqlParameter("inUserEmpID", OracleTypes.INTEGER)) .declareParameters(new SqlParameter("inCountryIDs", OracleTypes.ARRAY,

Spring JdbcTemplate “insert into.. select from..” not working

a 夏天 提交于 2019-12-10 12:07:17
问题 I am trying to execute following SQL with Spring JdbcTemplate: INSERT INTO japan_wht.PIVOT_20427002(doc_header_text, value_date, total_amt, is_refund) (SELECT doc_header_text, DATE(value_date), SUM(LOCAL_CCY_AMT), is_refund FROM (SELECT * FROM japan_wht.DATA_20427002 WHERE IS_REFUND in ('N') ) t GROUP BY DATE(value_date) , doc_header_text, is_refund) However, it does not insert anything into database table and no error is thrown. When I tried to execute following SQL with JdbcTemplate, it