bigint的NumberFormatting异常

问题描述

我将数据库用作postgresql,并通过spring jdbctemplate连接到数据库

数据库中的电话专栏为history and location春天来了phone bigint

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"

解决方法

您的问题出在int上。

在Java中,int可以容纳从-21474836482147483647的任何整数,并且您的值7894561230超出了它的范围。因此,请使用long代替int