Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请帮帮我registerOutParameter的问题 谢谢
Jsharp





发贴: 30
积分: 0
于 2006-08-03 02:11 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
数据库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的机制?
谢谢大家


Jsharp edited on 2006-08-03 02:21

作者 Re:请帮帮我registerOutParameter的问题 谢谢 [Re:Jsharp]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-08-03 08:52 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
money is 64-bit so it may lose precision with getDouble
check http://msdn2.microsoft.com/en-us/library/ms378680.aspx



作者 Re:请帮帮我registerOutParameter的问题 谢谢 [Re:Jsharp]
Jsharp





发贴: 30
积分: 0
于 2006-08-03 14:12 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
首先十分感谢 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
这句话无法通过.小弟愚笨,还烦请解释.



作者 Re:请帮帮我registerOutParameter的问题 谢谢 [Re:Jsharp]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-08-03 15:28 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
numeric, decimal, money map to BigDecimal
用Double接收 应该"有"问题
but you could try the lastest version of SQL Server JDBC driver



作者 Re:请帮帮我registerOutParameter的问题 谢谢 [Re:Jsharp]
Jsharp





发贴: 30
积分: 0
于 2006-08-03 15:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
萍水相逢,鼎立相助!!
而我却只能说谢谢.



作者 Re:请帮帮我registerOutParameter的问题 谢谢 [Re:Jsharp]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-08-03 16:23 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Sorry, I didn't read carefully:
double cash=cst.getDouble(2);




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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