Topic: 请帮帮我registerOutParameter的问题 谢谢

  Print this page

1.请帮帮我registerOutParameter的问题 谢谢 Copy to clipboard
Posted by: Jsharp
Posted on: 2006-08-03 02:11

数据库sqlserver2000
操作系统 xp2 个人版
IDE jbuilder 2005or2006
存储过程如下
create proc selectcash
@uid varchar(50),@cash money out
as
select @cash=cash from userinfo where uid=@uid
程式代码如下
try {
cst = conn.prepareCall("{call selectcash(?,?)}");
cst.setInt(1,id);//cst为定义过的CallableStatement的对象
cst.registerOutParameter(2,java.sql.Types.DECIMAL,3);
//cst.registerOutParameter(2,java.sql.Types.DOUBLE);
cst.execute();
//这里为什么不能用double?
java.math.BigDecimal cash=cst.getBigDecimal(2);
//Double cash=cst.getDouble(2);
System.out.println(cash);
} catch (SQLException ex) {
}
为什么不能用double类型接收sql中的money类型?还是java的机制?
谢谢大家

2.Re:请帮帮我registerOutParameter的问题 谢谢 [Re: Jsharp] Copy to clipboard
Posted by: why
Posted on: 2006-08-03 08:52

money is 64-bit so it may lose precision with getDouble
check http://msdn2.microsoft.com/en-us/library/ms378680.aspx

3.Re:请帮帮我registerOutParameter的问题 谢谢 [Re: Jsharp] Copy to clipboard
Posted by: Jsharp
Posted on: 2006-08-03 14:12

首先十分感谢 why 对我的教诲!
现在代码改为如下
try {
cst = conn.prepareCall("{call selectcash(?,?)}");
cst.setInt(1,id);//cst为定义过的CallableStatement的对象
cst.registerOutParameter(2,java.sql.Types.DOUBLE);
cst.execute();
Double cash=cst.getDouble(2);
System.out.println(cash);
} catch (SQLException ex) {
}
这个时候程式并不知道会接收一个什么样的返回数据类型,编译应该是没错的.
可问题是的确有错.
Double cash=cst.getDouble(2);
getDouble()返回一个double类型的数据 用Double接收 应该没问题啊
提示错误说是incompatible types
这句话无法通过.小弟愚笨,还烦请解释.

4.Re:请帮帮我registerOutParameter的问题 谢谢 [Re: Jsharp] Copy to clipboard
Posted by: why
Posted on: 2006-08-03 15:28

numeric, decimal, money map to BigDecimal
用Double接收 应该"有"问题
but you could try the lastest version of SQL Server JDBC driver

5.Re:请帮帮我registerOutParameter的问题 谢谢 [Re: Jsharp] Copy to clipboard
Posted by: Jsharp
Posted on: 2006-08-03 15:45

萍水相逢,鼎立相助!!
而我却只能说谢谢.

6.Re:请帮帮我registerOutParameter的问题 谢谢 [Re: Jsharp] Copy to clipboard
Posted by: why
Posted on: 2006-08-03 16:23

Sorry, I didn't read carefully:
double cash=cst.getDouble(2);


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923