Using queryforobject to query database
Integer id = jdbcTemplate.queryForObject(sql, Integer.class);
The following exception was encountered
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
The causes were found out
Queryforobject has and can only query one piece of data. If there is no such data in the database or the same data in the database, this exception will be thrown
Solution:
Use queryforlist to judge
List<Integer> list = jdbcTemplate.queryForList(sql, Integer.class);
Similar Posts:
- java.sql.SQLException: Fail to convert to internal
- Transaction rolled back because it has been marked as rollback-only
- [Solved] Spark Streaming:updateStateByKey is not applicable for the arguments…
- Streams AQ: enqueue blocked on low memory wait event causes slow expdp export
- [How to Solve] expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__
- [Solved] Mybatis error: attempted to return null from a method with a primitive return type (int)
- [solved] exception: Java. Lang. arithmeticexception / by zero
- [Solved] java.lang.IllegalArgumentException: id to load is required for loading
- Database Backup Error: mysqldump: Got error: 1146: Table ‘enwei_hq.tb_classification’ doesn’t exist when using LOCK TABLES
- [Solved] expected single matching bean but found 2