简体   繁体   中英

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 . On the study material I found this question:

Can I execute a plain SQL statement with the JDBC template?

What exactly is a plain SQL statement ? Is it a standard SQL query? 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:

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 .

What do you think about?

From my point of view:

  • a non-plain sql is a query in jql.
  • Some stuff is quite complicate to achive with jql (ie. joins over a few tables) in an already existent data scheme.
  • jpa requests primary keys in tables - which is not always the case in existent databases
  • the question aims on 'i wanna have a fallback to traditional queries to do my everyday's life'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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