numberformating异常

bqucvtff  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(232)

我使用数据库作为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;
}
nnsrf1az

nnsrf1az1#

你的问题在于 int .
在java中 int 可以容纳来自 -21474836482147483647 还有你的价值 7894561230 超出范围。所以使用 long 代替 int .

相关问题