简体   繁体   English

我可以使用Spring JDBC模板执行纯SQL语句吗?

[英]Can I execute a plain SQL statement with the Spring JDBC template?

I am studying for the Spring Core certification and I have some doubts about the use of JdbcTemplate . 我正在学习Spring Core认证,我对JdbcTemplate的使用有些怀疑。 On the study material I found this question: 在研究材料上我发现了这个问题:

Can I execute a plain SQL statement with the JDBC template? 我可以使用JDBC模板执行纯SQL语句吗?

What exactly is a plain SQL statement ? 究竟什么是简单的SQL语句 Is it a standard SQL query? 它是标准的SQL查询吗? or what? 要不然是啥?

If it is a standard SQL query (not something like JPQL) I think that the answer is yes because I can do something like it: 如果它是标准的SQL查询(不是像JPQL那样),我认为答案是肯定的,因为我可以做类似的事情:

public Date getOldest() {
    String sql = “select max(dob) from PERSON”;
    return jdbcTemplate.queryForObject(sql, Date.class);
}

public long getPersonCount() {
    String sql = “select count(*) from PERSON”;
    return jdbcTemplate.queryForObject(sql, Long.class);
}

But I am absolutly not sure to have understand the sense of the question and what exactly represent a plain SQL statement . 但我绝对不确定理解问题的意义以及究竟代表一个简单的SQL语句

What do you think about? 你有什么想法?

From my point of view: 从我的角度来看:

  • a non-plain sql is a query in jql. 非普通sql是jql中的一个查询。
  • Some stuff is quite complicate to achive with jql (ie. joins over a few tables) in an already existent data scheme. 在已经存在的数据方案中,有些东西对于使用jql(即连接几个表)非常复杂。
  • jpa requests primary keys in tables - which is not always the case in existent databases jpa请求表中的主键 - 在现有数据库中并不总是如此
  • the question aims on 'i wanna have a fallback to traditional queries to do my everyday's life' 这个问题的目标是“我想回归传统的问题来做我的日常生活”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM