jdbc4 - 如何插入货币类型?
我遇到了一个有趣的问题...我有 MSSQL (2005) 表 A,其中包含货币类型列;问题是我想通过 Java 代码中的 T-SQL 过程调用向该列插入值,但我不太确定应该使用哪种 Java 类型来准备该列插入值的语句? 我找不到任何示例,因此也许您可以分享一些有用的片段。
任何有用的评论表示赞赏
I faced an interesting problem as... I have MSSQL (2005) table A which contains money type column; the thing is I want to insert value to this column with T-SQL procedure call from Java code but I am not pretty sure which Java type should I use to prepare statement for this column to insert value?
I couldn't find any example so maybe you can share some helpful snippets.
Any useful comment is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道你不能只使用
double
(或者也许float
,但可能不是)?另外,通过在数据库中使用MONEY
您可以获得什么?我发现DECIMAL
更加可靠和灵活 - 有关一些背景信息,请参阅 要戒掉的坏习惯:选择错误的数据类型和性能/存储比较:MONEY 与 DECIMAL (抱歉缺少图片)。Couldn't you just use a
double
(or maybefloat
, but probably not)? Also, what are you gaining by usingMONEY
in your database? I've foundDECIMAL
to be much more reliable and flexible - for some background see Bad habits to kick : choosing the wrong data type and Performance / Storage Comparisons : MONEY vs. DECIMAL (sorry for missing images).好的...
我能弄清楚的是不要直接使用资金类型只是因为jdbc4连接器PrepareSatement不包含setMoney等所以我想分享一些走动...当然,这不是最终的代码方式但仍然...
所以
A) Money 类从这里获取字符串$00.00 与
displayAsDollars 方法
B) 使用如下代码创建 mssql 过程
//...
正如我所说,这不是最终的代码决定,而是一个临时概念,如果您确实需要在旧的 mssql 数据库中使用资金类型。至少对我来说这是一个临时答案:)
我希望这对某人有帮助:)
祝你好运
OK...
things I could figure out is NOT TO USE money type directly just because the jdbc4 connector PrepareSatement does not contain setMoney etc so I want to share some walk around... Of course, it is not the final code way but still...
So
A) Money class from here to get string as $00.00 with
displayAsDollars method
B) create mssql procedure with code like a
C) So the proc call is quite simple as
//...
As I was saying it is not the final code decision but a temp conception which may be helpful as well if you really need to use money type in your old mssql database. At least it was a temp answer in my case :)
I hope it will be helpful for someone :)
Good luck