How to pass Table-Valued Parameters (Array-like Parameter) to Stored Procedure in Microsoft SQL Server 2008 R2 using JDBC? [duplicate]
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?
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.
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:
SQLServerDataTable table = new SQLServerDataTable();
table.addColumnMetadata("i" ,java.sql.Types.INTEGER);
table.addRow(1);
table.addRow(2);
table.addRow(3);
table.addRow(4);
try (SQLServerPreparedStatement stmt=
(SQLServerPreparedStatement) connection.prepareStatement(
"SELECT * FROM some_table_valued_function(?)")) {
// Magic here:
stmt.setStructured(1, "dbo.numbers", table);
try (ResultSet rs = stmt.executeQuery()) {
...
}
}
I've also recently blogged about this here.
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.
精彩评论