spring - JdbcTemplate - 替换问号

标签 spring jdbc spring-boot spring-jdbc jdbctemplate

我有一个sql查询。

String sql = "SELECT ? FROM Users WHERE Lastname=?";

我使用 JDBCTemplate 中的 queryForList 方法

Object [] myparams = {"name", "Doe"};
int [] mytypes = {Types.VARCHAR, Types.VARCHAR};
List<Map<String,Object>> listOfMaps = jdbc.queryForList(sql, myparams, mytypes);

输出不正确,因为第一个问号有问题。我以为问号会被 myparams 数组中的参数替换,但事实并非如此。

是否可以实现我想要实现的目标,但不能通过手动向字符串添加参数来实现?

最佳答案

只能对 where 语句中的参数使用问号。

关于spring - JdbcTemplate - 替换问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758477/

相关文章:

mysql - Spring Boot 中的外键(MySQL、Hibernate、JPA)

Spring hibernate 手动提交

java - SimpleGrantedAuthority 无法解析

java - ClassNotFoundException Class.forName ("com.mysql.jdbc.Driver");

amazon-web-services - AWS Glue to Redshift : Is it possible to replace, 更新还是删除数据?

java - springboot @EnableConfigurationProperties 不起作用

spring - 在 Spring Boot 应用程序中将多个调用包装在一个事务中?

spring-boot 自定义 Jetty SSLContextFactory

spring - Kotlin Autowired问题-Lateinit(OBV)

java - 在 JDBC for PostgreSQL 中,我可以执行 psql 命令吗?