如何使用 JDBC 将表值参数(类似数组的参数)传递给 Microsoft SQL Server 2008 R2 中的存储过程?
如何使用 Microsoft SQL Server 2008 R2 JDBC 驱动程序将表值参数(类似数组的参数)传递给 Microsoft SQL Server 2008 R2 中的存储过程? jTDS 可以吗?
How to pass Table-Valued Parameters (Array-like Parameter) to Stored Procedure in Microsoft SQL Server 2008 R2 using Microsoft SQL Server 2008 R2 JDBC Driver ?
Is it possible with jTDS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当前 (3.0) Microsoft 驱动程序不支持传递 TVP。
微软曾一度为 TVP 与 Bulk Copy 征求投票:
http://blogs.msdn.com/b/jdbcteam/archive/2011/09/22/tvp-or-bulk-copy.aspx
TVP 获得了更多选票,但仍看看实际做了什么。最新的 CTP 4.0 版似乎不支持 TVP。
The current (3.0) Microsoft driver doesn't support passing TVPs.
At one point, Microsoft was soliciting votes for TVP vs. Bulk Copy:
http://blogs.msdn.com/b/jdbcteam/archive/2011/09/22/tvp-or-bulk-copy.aspx
TVP got more votes, but it remains to be seen what actually got done. The most recent CTP for version 4.0 doesn't appear to have TVP support.
虽然这个问题是关于 SQL Server 2008 的,而且当时确实不可能传递表值参数,但现在可以了。 JDBC 驱动程序手册。例如,可以这样做:
我最近也在此处发表了有关此内容的博客。
While this question was about SQL Server 2008, and while it really wasn't possible to pass table valued parameters at the time, it is now. This is documented here in the JDBC driver manual. For example, it could be done like this:
I've also recently blogged about this here.
我自己解决了这个问题。我创建了 CLR .Net Stored Proc 并接受 BLOB 参数。这个 BLOB 只是序列化 INT 的列表。可以使用 T-SQL 或 .Net CLR SP 对其进行反序列化。
.Net CLR SP 具有更好的性能,这对我的项目非常重要。
I have solved this problem by myself. I have created CLR .Net Stored Proc with accepts a BLOB parameter. This BLOB is just a list of serialized INTs. It is possible to deserialize it using T-SQL or .Net CLR SP.
.Net CLR SP has better performance, which was really important for my project.