更新时间:2023-02-07 12:08:40
是的,现在可以了.用于 SQL Server 的 Microsoft JDBC 驱动程序 6.0 版增加了对表值参数的支持.
Yes, it is now possible. Version 6.0 of Microsoft's JDBC driver for SQL Server added support for table-valued parameters.
以下代码示例展示了如何
The following code sample shows how to
SQLServerDataTable
对象来保存要传递的表数据,以及SQLServerCallableStatement#setStructured
方法将该表传递给存储过程.SQLServerDataTable
object to hold the table data to be passed, and SQLServerCallableStatement#setStructured
method to pass that table to the stored procedure.SQLServerDataTable sourceDataTable = new SQLServerDataTable();
sourceDataTable.addColumnMetadata("SDate", java.sql.Types.DECIMAL);
sourceDataTable.addColumnMetadata("EDate", java.sql.Types.DECIMAL);
sourceDataTable.addColumnMetadata("PlantCode", java.sql.Types.NVARCHAR);
sourceDataTable.addColumnMetadata("LoadType", java.sql.Types.NCHAR);
sourceDataTable.addColumnMetadata("Asset", java.sql.Types.BIGINT);
// sample data
sourceDataTable.addRow(123, 234, "Plant1", "Type1", 123234);
sourceDataTable.addRow(456, 789, "Plant2", "Type2", 456789);
try (CallableStatement cs = conn.prepareCall("{CALL dbo.RegisterInitAssets (?)}")) {
((SQLServerCallableStatement) cs).setStructured(1, "dbo.INITVALS_MSG", sourceDataTable);
boolean resultSetReturned = cs.execute();
if (resultSetReturned) {
try (ResultSet rs = cs.getResultSet()) {
rs.next();
System.out.println(rs.getInt(1));
}
}
}
有关详细信息,请参阅以下 MSDN 文章:
For more details, see the following MSDN article: