jdbctemplate

jdbctemplate之BeanPropertyRowMapper

余生颓废 提交于 2019-12-10 07:15:46
今天看SpringAPI的时候无意中发现了Spring2.5新增了一个RowMapper的实现类org.springframework.jdbc.core.BeanPropertyRowMapper,但是貌似Spring的refrence里面根本就没提及到。Google了一下……貌似也莫得多少文档。 Spring API Doc的说明如下: RowMapper implementation that converts a row into a new instance of the specified mapped target class. The mapped target class must be a top-level class and it must have a default or no-arg constructor. Column values are mapped based on matching the column name as obtained from result set metadata to public setters for the corresponding properties. The names are matched either directly or by transforming a name separating

java.sql.SQLException: Invalid column name

最后都变了- 提交于 2019-12-10 03:28: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' " +

Spring框架JdbcTemplate类中查询方法介绍

霸气de小男生 提交于 2019-12-09 17:59:37
本文使用 Spring2.5.6.SEC02 和 JDK1.4 作为讲解环境。 Spring 框架中 org.springframework.jdbc.core 包提供了 JDBC 模板类,其中 JdbcTemplate 是 core 包的核心类,其他模板类都是基于它封装完成的。 Spring 除了提供 JdbcTemplate 核心 类外,还提供了基于 JdbcTemplate 实现的 NamedParameterJdbcTemplate 类用于支持命名参数绑定、 SimpleJdbcTemplate 类用于支持 JDK5+ 的可变参数及自动装箱拆箱等特性。本文主要介绍 JdbcTemplate 核心类。 JdbcTemplate 类主要提供以下四类方法: execute 方法:用于执行任何 SQL 语句,一般用于执行 DDL 语句; update 方法及 batchUpdate 方法: update 方法用于执行新增、修改、删除等语句 ,batchUpdate 方法用于执行批处理相关语句; query 方法及 queryForXXX 方法:用于执行查询相关语句; c all 方法:用于执行存储过程、函数相关语句。 下面将主要介绍 query 方法及 queryForXXX 方法的返回值和相关异常。 首先我们先大概了解下 query 方法及 queryForXXX 方法的调用层次

jeecg随笔

核能气质少年 提交于 2019-12-09 17:24:08
1.根据数据字典code查找该字典下的元素: SELECT typecode,typename from t_s_type where typegroupid=(select id from t_s_typegroup where typegroupcode='fchexing') fchexing为字典的code <t:dictSelect field="transMode" typeGroupCode="orderCj" extendJson="{onchange:'fun_tel()'}" title="成交方式" ></t:dictSelect> 2.jdbcTemplate,jeecgMinidaoDao类的引入 @Resource private JdbcTemplate jdbcTemplate; @Autowired private JeecgMinidaoDao jeecgMinidaoDao; 3.获取当前登录用户的实体类 TSUser user = ResourceUtil.getSessionUserName();//老版本 TSUser user = ResourceUtil.getSessionUser();//新版本 List<TSRoleUser> rUsers1 = systemService.findByProperty(TSRoleUser

spring boot 系列之六:深入理解spring boot的自动配置

99封情书 提交于 2019-12-09 10:19:22
我们知道,spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate是不是在Classpath里面?如果是,并且DataSource也存在,就自动配置一个JdbcTemplate的Bean Thymeleaf是不是在Classpath里面?如果是,则自动配置Thymeleaf的模板解析器、视图解析器、模板引擎 那个这个是怎么实现的呢?原因就在于它利用了Spring的条件化配置,条件化配置允许配置存在于应用中,但是在满足某些特定条件前会忽略这些配置。 要实现条件化配置我们要用到@Conditional条件化注解。 本篇随便讲从如下三个方面进行展开: @Conditional小例子,来说明条件化配置的实现方式 spring boot 的条件化配置详解 spring boot 自动配置源码分析 自己动手实现spring boot starter pom 一、@Conditional小例子 我们知道在windows下显示列表的命令是dir,而在linux系统下显示列表的命令是ls,基于条件配置,我们可以实现在不同的操作系统下返回不同的值。 判断条件定义 )windows下的判定条件 /** * 实现spring 的Condition接口,并且重写matches()方法

JdbcTemplate query close database connection

大兔子大兔子 提交于 2019-12-09 05:25:55
问题 I use jpa with hibernate. I have following method: @Transactional public void myMethod(){ ... firstJDBCTemplateQuery(); secondJDBCTemplateQuery(); ... } firstJDBCTemplateQuery works, but it closes connection to database. When second secondJDBCTempolateQuery is executed java.sql.SQLException: Connection is closed exception is thrown what causes org.springframework.transaction.TransactionSystemException: Could not roll back JPA transaction ... My configuration: EDIT <bean id="dataSource" class=

JavaWeb_(Spring框架)Spring与JDBC

只谈情不闲聊 提交于 2019-12-08 19:56:27
一、用Spring中的JdbcTemplate操作数据库   在MySQL中准备一个user表,表中增加一条假数据      用Spring中的JdbcTemplate操作数据库,在JdbcTemplate中实现增删改查操作 //增 void saveUser(User u); //删 void deleteUserById(Integer id); //改 void updateUser(User u); //查 //根据id查找用户 User selectUserById(Integer id); //查找全部用户List List<User> selectAllUser(); //查找用户数量 Integer selectUserCount(); package com.Gary.bean; public class User { private Integer u_id; private String u_username; private String u_password; public Integer getU_id() { return u_id; } public void setU_id(Integer u_id) { this.u_id = u_id; } public String getU_username() { return u_username; }

Spring transactions not working + JAX WS + JDBC

眉间皱痕 提交于 2019-12-08 19:32:34
问题 I'm a bit exasperated with this issue. Lets check if someone has implemented something similar. I have a java 8 web application with 8 WS implemented. Some of this WS, make inserts and updates through JDBCTemplate (Hibernate is not a choice due to performance needs) and i need them to rollback if execution crashes with an exception. I have the following configuration of datasource and transaction manager in spring app context file (jndi resource in server.xml/context.xml of Tomcat): <bean id=

Spring (MVC) SQL injection avoidance?

时光毁灭记忆、已成空白 提交于 2019-12-08 15:46:46
问题 I am wondering how Spring MVC handles SQL injections (and other security issues: XSS, code [javascript] injection, etc). I'm talking mostly about escaping the values that are added to DBs and such. I can't seem to find any answer because every time I search for spring sql injection results that involve dependency injection arise. My flow is as follows: from the client browser I make a request consisting of an JSON with some query parameters (not the SQL statement, that would be too stupid -

NamedJDBCTemplate Parameters is list of lists

两盒软妹~` 提交于 2019-12-08 07:12:48
问题 I have a query which looks something like this: SELECT * FROM someTable t WHERE (t.a, t.b) IN (VALUES (1, 2), (3, 4)) And it would select any records where t.a == 1 AND t.b == 2 or t.a == 3 AND t.b == 4 . This seems to work just fine. However, I can't figure out a clean way to specify the parameter to NamedJDBCTemplate . I tried giving it a list of lists (i.e., List<List<int>> ), but it seems to blow up doing that. val query = "SELECT * FROM someTable t WHERE (t.a, t.b) IN (VALUES :values)"