<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
我正在使用 jdbcTemplate ,并且在调用方法findyByUsername
时出现以下异常:
org.postgresql.util.PSQLException: ResultSet is closed.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2839) ~[postgresql-9.3-1100-jdbc41.jar:na]
...
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:612) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:700) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:712) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:783) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at at.muaz.StudentManagement.dao.MySqlData.findByUsername(MySqlData.java:33) ~[classes/:na]
at at.muaz.StudentManagement.dao.MySqlData$$FastClassBySpringCGLIB$$f817516e.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE].....
方法findyByUsername
:
@Override
public Student findByUsername(String username){
String sql = "SELECT * FROM student WHERE student.name = ?";
return jdbcTemplate.queryForObject(sql, new Object[]{username}, (rs, i) ->
new Student(
UUID.fromString(rs.getString("id")),
rs.getString("name"),
rs.getString("lastName"),
rs.getString("password"),
rs.getString("gender"),
rs.getString("number"),
rs.getString("email"),
rs.getString("role")
));
}
我以前使用phpMyAdmin作为数据库。
我想尝试postgres,所以我将所有表从phpMyAdmin复制到了postgres。
我还用id
替换了UUID
,后者是一个较早的整数,我认为不会导致错误。
答案 0 :(得分:-1)
我通过更改版本进行了修复。我只是将版本替换为:
CorrespondenceRejector