jdbcTemplate常见用法整理。
来源:互联网 发布:淘宝cpu散片哪家靠谱 编辑:程序博客网 时间:2024/06/06 07:36
返回list类型String sql = "select * from " + Constant.WEBDBNAME +".coninfo_classification where userid = ?";List<ConnClassification> list = jdbcTemplate.query(sql, new Object[]{userid},ParameterizedBeanPropertyRowMapper.newInstance(ConnClassification.class));插入返回插入自增主键idpublic int createFolder(int userid,String foldername,String usercomefrom){String ctime = Util.dateFormat2(new Date());String sql ="insert into " + Constant.WEBDBNAME +".coninfo_classification(userid,name,usercomefrom,createtime) VALUES(?,?,?,?);";KeyHolder keyHolder = new GeneratedKeyHolder();int id =0;try {jdbcTemplate.update(new PreparedStatementCreator() {public PreparedStatement createPreparedStatement(Connection arg0) throws SQLException {PreparedStatement ps = arg0.prepareStatement(sql);ps.setInt(1,userid );ps.setString(2,foldername);ps.setString(3,usercomefrom);ps.setString(4,ctime);return ps;}}, keyHolder);id = keyHolder.getKey().intValue();} catch (Exception e) {e.printStackTrace();}return id;}同时修改,插入多条信息(只执行一次sql)/** * 批量随机更新资源库成果需求配图 * @author shen.guoliang * @version 1.0, 2017年7月3日 * @param piclist参数说明 * @see[类,类#方法,类#成员] * @since[产品/模块版本] 表示从那个版本开始就有这个方法 */ public int updatePic(List<ProjectModel> prilist){ String sql = "update " + Constant.WEBDBNAME + ".technical_info set imgname =? where id = ? and project_type_id =?";List<Object[]> args = new ArrayList<>();if (prilist != null && prilist.size() > 0) {for (int i = 0; i < prilist.size(); i++) {ProjectModel pic = prilist.get(i);Object[] obj = new Object[Constant.NUM_3];obj[0] = pic.getImgname();obj[1] = pic.getId();obj[2] = pic.getProjectTypeId();args.add(obj);}int[] ret = jdbcTemplate.batchUpdate(sql, args);args = null;return ret.length;}return 0; }
阅读全文
0 0
- jdbcTemplate常见用法整理。
- C++常见用法规范整理
- STL常见用法整理_queue
- STL常见用法整理_set
- STL常见用法整理_multiset
- STL常见用法整理_list
- STL常见用法整理_remove_if
- Logcat过滤及常见用法整理
- Logcat过滤及常见用法整理
- Logcat过滤及常见用法整理
- STL常见用法整理_队列
- dfs序的常见用法整理
- Android Drawable常见子类及其用法整理
- jdbcTemplate.update(...)的用法
- jdbcTemplate.queryXX 方法用法
- Spring JdbcTemplate 用法总结!!!
- JdbcTemplate的用法
- Spring JdbcTemplate 用法总结!!!
- [每日高赞翻译stackoverflow](1)string 和 String 的区别
- Linux下的软件Mysql完全卸载(包括其依赖和库等残留文件)
- Hibernate懒加载异常: org.hibernate.LazyInitializationException: could not initialize proxy
- 软件测试分类
- 性能测试:响应时间/并发用户数/吞吐量/思考时间的计算
- jdbcTemplate常见用法整理。
- 上线打包出现错误整理90362,90535,4238
- 使用jsencrypt实现参数的前端加密
- VirtualBox for mac调整虚拟机硬盘大小
- 面试题61:按之字型顺序打印二叉树
- thinkphp5 源码分析二 框架引导
- 通过实现Runnable接口创建线程
- C++中的static关键字的总结
- linux下tar的打包使用