英文:
NumberFormatting exception for bigint
问题
我正在使用PostgreSQL作为数据库,在Spring JdbcTemplate中连接到数据库。
数据库中的电话列为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;
}
**错误:-**
> 输入字符串为:"7894561230";嵌套异常是
> java.lang.NumberFormatException:输入字符串为:"7894561230"
我的Bean类是:
public class UserDetails {
private int userId;
private String name;
private String email;
private String phone;
}
英文:
I am using database as postgresql, connecting to the database with spring jdbctemplate.
The phone column in database is phone bigint
The spring is throwing the 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"
My Bean is :-
public class UserDetails {
private int userId;
private String name;
private String email;
private String phone;
}
答案1
得分: 0
你的问题出在 int
上。
在Java中,int
可以容纳从 -2147483648
到 2147483647
的任何整数,而你的值 7894561230
超出了其范围。因此请使用 long
替代 int
。
英文:
You problem is with int
.
In Java int
can hold any whole number from -2147483648
to 2147483647
and your value 7894561230
is out of range for it. So use long
in place of int
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论