我使用数据库作为postgresql,用springjdbctemplate连接到数据库。
数据库中的phone列是 phone bigint
Spring在抛洒阳光 java.lang.NumberFormatException
```
public UserDetails getUserDetails(int phone) {
String sql = "SELECT * FROM users where phone = ?";
UserDetails users = (UserDetails) jdbcTemplate.query(sql,new Object[]{phone},
new BeanPropertyRowMapper<UserDetails>(UserDetails.class));
return users;
}
Error:-
For input string: "7894561230"; nested exception is
java.lang.NumberFormatException: For input string: "7894561230"
我的想法是:-
public class UserDetails {
private int userId;
private String name;
private String email;
private String phone;
}
1条答案
按热度按时间nnsrf1az1#
你的问题在于
int
.在java中
int
可以容纳来自-2147483648
至2147483647
还有你的价值7894561230
超出范围。所以使用long
代替int
.