首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Spring预准备语句中传递Java日期

如何在Spring预准备语句中传递Java日期
EN

Stack Overflow用户
提问于 2017-08-24 18:34:04
回答 1查看 64关注 0票数 2

如果我有一个Java Date,并且使用JDBCTEmplate,我想在预准备语句中使用它,这是正确的语法吗?

代码语言:javascript
运行
复制
Date x = new Date();

...

String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and a.date = ?";

A istance = jdbcTemplate.queryForObject(SQL, new Object[]{variable_1, variable_2, x}, new aAndbMapper());

或者我应该这样写:

代码语言:javascript
运行
复制
String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and DATE(a.date) = ?";
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-24 20:52:17

第一个是一个很好的选择,不过我会在没有自定义映射器的情况下这样做:

代码语言:javascript
运行
复制
String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and a.date = ?";

A istance = getJdbcTemplate().queryForObject(SQL, new Object[]{variable_1, variable_2, x}, new BeanPropertyRowMapper(A.class));

有关beanPropertymapper的更多信息:Documentation

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45859310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档