[英]Inserting to Numeric field using prepared statement
我嘗試使用准備好的語句將值插入SQL Server數字字段:
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 Server的“數字”字段中?
原來,當您將String轉換為int時,由於某種原因,在嘗試插入准備好的語句時,該轉換不起作用。
int temp= 2;
type = java.sql.Types.NUMERIC;
System.out.println(temp);
prd.setObject(i+1, temp,type);
這樣可行。
在我的初始代碼中,我做了:Integer.parseInt(String_value),由於某種原因,它破壞了變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.