jdbctemplate

java.sql.SQLException: Invalid column name

二次信任 提交于 2019-12-05 02:56:59
I cannot figure out why I am getting "Invalid column name" here. We have tried a variant of the sql directly in Oracle, and it works fine, but when I try it using jdbcTemplate then something is wrong. List<Dataholder> alleXmler = jdbcTemplate.query("select p.applicationid, x.datadocumentid, x.datadocumentxml " + "from CFUSERENGINE51.PROCESSENGINE p " + "left join CFUSERENGINE51.DATADOCUMENTXML x " + "on p.processengineguid = x.processengineguid " + "where x.datadocumentid = 'Disbursment' " + "and p.phasecacheid = 'Disbursed' ", (rs, rowNum) -> { return Dataholder.builder() .applicationid(rs

Spring Jdbc浅谈

a 夏天 提交于 2019-12-04 21:54:47
1.配置 在maven文件src/main/resources位置上配置一个applicationContext-jdbc.xml文件用来做配置。   <1>JdbcTemplate的配置       即配置dataSource装入连接池数据作为jdbcTemplate的属性 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${mysql_driver}"></property> <property name="url" value="${mysql_url}"></property> <property name="username" value="${mysql_username}"></property> <property name="password" value="${mysql_passwd}"></property> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> <

spring JdbcTemplate的CRUD操作

六月ゝ 毕业季﹏ 提交于 2019-12-04 20:57:49
package com.com.jdbctemplate; import com.com.domain.Account; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import java.util.List; /** * spirng JdbcTemplate在spring中的ioc中使用 */ public class JDBCTemplateDemo3 { public static void main(String[] args) { //1.获取spirng的核心容器 ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); //2.获取对象 JdbcTemplate jt = ac.getBean("jdbcTemplate",

How to insert blob using camel SQL component with Oracle Database

依然范特西╮ 提交于 2019-12-04 19:12:00
I am trying to insert an input stream using camel SQL component ( http://camel.apache.org/sql-component.html ). I have the following table in Oracle Database: table EMPLOYEE(NAME varchar(32) ,SURNAME varchar(32) , PIC BLOB ); and the following route: <route> <from uri="direct:startOracle" /> <to uri="sql:INSERT INTO EMPLOYEE (Name, surname, pics) VALUES (# , # , #)?dataSource=#oracle" /> </route> when I try to run the following code: Resource r = contex.getResource("classpath:file/ciao.jpg"); InputStream inputStream = r.getInputStream(); aProducerTemplate.sendBody(new Object[] {"mario", "ross"

Spring JDBC最佳实践(2)

你。 提交于 2019-12-04 19:07:44
使用DataSourceUtils进行Connection的管理 由上节代码可知,JdbcTemplate在获取Connection的时候,并不是直接调用DataSource的getConnection(),而是调用了如下的代码: Connection con = DataSourceUtils.getConnection(getDataSource()); 为什么要这么做呢? 实际上,如果对于一个功能带一的JdbcTemplate来说,调用如下的代码就够了: Connection con = dataSource.getConnection(); 只不过,spring所提供的JdbcTemplate要关注更多的东西,所以,在从dataSource取得连接的时候,需要多做一些事情。 org.springframework.jdbc.datasource.DataSourceUtils所提供的方法,用来从指定的DataSource中获取或者释放连接,它会将取得的Connection绑定到当前的线程,以便在使用Spring所提供的统一事务抽象层进行事务管理的时候使用。 为什么要使用NativeJdbcExtractor 在execute()方法中可以看到: if (this.nativeJdbcExtractor != null && this.nativeJdbcExtractor

Spring的JdbcTemplate使用教程

守給你的承諾、 提交于 2019-12-04 18:26:11
Spring对数据库的操作在jdbc上面做了基本的封装,让开发者在操作数据库时只需关注SQL语句和查询 结果处理器,即可完成功能(当然,只使用JdbcTemplate,还不能摆脱持久层实现类的编写)。 在配合spring的IoC功能,可以把DataSource注册到JdbcTemplate之中。同时利用spring基于 aop的事务即可完成简单的数据库CRUD操作。 JdbcTemplate的限定命名为org.springframework.jdbc.core.JdbcTemplate。要使用 JdbcTemlate需要导入spring-jdbc和spring-tx两个坐标。 方法说明: execute方法: 可以用于执行任何SQL语句,一般用于执行DDL语句; update方法及batchUpdate方法: update方法用于执行新增、修改、删除等语句;batchUpdate方法用于执行批处理相关语 句; query方法及queryForXXX方法: 用于执行查询相关语句; call方法: 用于执行存储过程、函数相关语句。 使用案例 项目结构: POM.XML <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId>

How to call a stored procedure with ref cursor as an output parameter using Spring?

北慕城南 提交于 2019-12-04 17:28:28
I have a stored procedure which has body like :- PROCEDURE PROC_NAME(param1 in varchar2,param2 in varchar2,results_cursor OUT CURSOR_TYPE); Each row of result is equivalent to an instance of a certain user defined class. How can I call this in Spring. I went through lot of google and stackoverflow but could not find an apt answer. Can anyone please provide me a solution to this. Thanks in advance. Luke Woodward Here's something I put together based on this StackOverflow question and the Spring documentation : import java.sql.Types; import java.util.HashMap; import java.util.Map; import javax

how to query for a list<String> in jdbctemplate

隐身守侯 提交于 2019-12-04 16:24:48
问题 I'm using springs jdbctemplate and running a query like below: SELECT COLNAME FROM TABLEA GROUP BY COLNAME There are no named parameters being passed, however, column name, COLNAME , will be passed by the user. Questions Is there a way to have placeholders, like ? for column names? For example SELECT ? FROM TABLEA GROUP BY ? If I want to simply run the above query and get a List<String> what is the best way? Currently I'm doing: List <Map<String, Object>> data = getJdbcTemplate().queryForList

Oracle data source connection pooling not working used with Spring and JDBCTemplate

五迷三道 提交于 2019-12-04 15:56:51
Question: Lot of active unclosed physical connections with database even with connection pooling. Can someone tell me why is it so? I configured the connection pool settings using oracle.jdbc.pool.OracleDataSource . However it seems the physical connections are not getting closed after use. I thought, Since it is connection pooling, the connections will be reused from the pool, so so many physical connections will not be made, but thats not what is happening now! There are 100+ active physical connections in the database generating from the application [not from plsql developer or any such

spring02

亡梦爱人 提交于 2019-12-04 15:53:13
jdbcTemplate的使用 c3p0&&dbcp DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种,由Apache开发 C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate,Spring等。 dbcp没有自动回收空闲连接的功能 c3p0有自动回收空闲连接功能 bean.xml 1 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 2 <property name="dataSource" ref="dataSource"></property> 3 </bean> 4 5 <!-- 配置数据源--> 6 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 7 <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> 8 <property name="url" value="jdbc:mysql:/