package com.brookfieldres.operations;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import jav
This may not be exactly what you were hoping for, but it does work for passing parameters to the stored procedure by name, thereby allowing us to
For the stored procedure
CREATE PROCEDURE [dbo].[my_sp]
@p1 nvarchar(10) = N'Hello',
@p2 nvarchar(10) = N'world'
AS
BEGIN
SET NOCOUNT ON;
SELECT @p1 + N', ' + @p2 + N'!' AS response;
END
the JDBC call
try (CallableStatement s = conn.prepareCall("{CALL my_sp (@p2=?)}")) {
s.setString(1, "Gord");
try (ResultSet rs = s.executeQuery()) {
rs.next();
System.out.println(rs.getString("response"));
}
}
returns
Hello, Gord!
(Tested with Microsoft JDBC Driver 4.1 for SQL Server.)
Use index based set methods.
_cs = getConnection().prepareCall("{call iCurrentLocations01(?, ?, ?, ?)}");
_cs.setTimestamp(1, RunDate);
_cs.setString(2, rlpCompanyid);
_cs.setString(3, rlpLocationid);
_cs.setString(4, rlpOpenDate );
returnVal = _cs.executeUpdate();
System.out.println("2");