0

我尝试使用准备好的语句向 SQL 服务器数字字段插入一个值:

int temp = 5;
type = java.sql.Types.NUMERIC;                      
System.out.println(temp);
prd.setObject(i+1, temp,type);

但这给了我一个"Arithmetic overflow error converting numeric to data type numeric".

我还尝试将 int 转换为 Number 或使用 插入它prd.setInt,但这也不起作用。

在准备好的语句中设置值的正确方法是什么,它将成功插入到 SQL 服务器数字字段中?

4

1 回答 1

0

事实证明,当您将 String 转换为 int 时,由于某种原因,在尝试插入准备好的语句时转换不起作用。

int temp= 2;
type = java.sql.Types.NUMERIC;                      
System.out.println(temp);
prd.setObject(i+1, temp,type);

这样可行。

在我的初始代码中,我做了: Integer.parseInt(String_value) 并且由于某种原因破坏了变量。

于 2012-12-18T14:43:44.680 回答