java - SQLException: Select 语句抛出异常 The index 1 is out of range
问题描述
我尝试连接到 MS SQL Server,但是当我首次使用它时,我得到了 SQLException。
PreparedStatementCallback; SQL [select * from dbo.theLogin tl;]; 索引 1 超出范围
public ArrayList<Login> select(String username, String password) {
JdbcTemplate select = new JdbcTemplate(dataSource);
return (ArrayList<Login>) select.query(
"select tl.username, tl.password from dbo.theLogin tl;",
new Object[] {username, password},
new LoginRowMapper());
}
我无法弄清楚它有什么问题。请帮忙。预先感谢
解决方案
The second parameter to your query()
call should be a list of values to use to bind to any variables in the SQL statement - but your SQL does not have any variables to bind to, so you get that "index 1 is out of range" when it tries to set the first parameter to the value of username
. Your SQL looks like it will return a list of all username and password pairs from your table - which may not be what you were after...
推荐阅读
- html - 除非我在浏览器的开发工具中编辑文件,否则不会为规则解析 CSS 样式表
- xml - XSLT - text() 连接单词
- java - AuthenticationProvider 未进行身份验证
- javascript - 为什么'addEventListener'只适用于'for循环'
- sketchapp - Sketch 应用程序中的文本环绕
- javascript - 如何像 jQuery 一样过滤 vanilla Javascript 中的元素?
- c# - 内部选择查询和性能
- android - 为 Android 编译 IOzone 可执行文件
- ruby-on-rails - 在 Rails 上实例化子类 Ruby 的正确方法
- java - 命令在终端中工作,但使用 Process.exec 时出现“没有结束引号”错误