Driver version or jar name
mssql-jdbc verion 6.2.1.jre8
SQL Server version
Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) - 13.0.1742.0 (X64) Jul 5 2017 23:41:17 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows 8.1 Pro 6.3 (Build 9600: )
Client operating system
Windows 8.1
Java/JVM version
1.8
Table schema
Please tell us the table schema
Problem description
For mssql-jdbc the parameter names returned by DatabaseMetaData#getProcedureColumns do not match the names accepted by CallableStatement#setInt et. al..
Link to the problem on stackoverflow put up by me:
Expected behavior and actual behavior
I am trying to execute a stored procedure using SQL Server JDBC in a method using CallableStatement:
CallableStatement st = connection.prepareCall ("{ call ABC ( ? ) }");
Let say the stored procedure name is ABC and parameter is @a. Now DatabaseMetaData returns column name @a but setting st.setInt("@a",0) returns following error:
com.microsoft.sqlserver.jdbc.SQLServerException: Parameter @a was not defined for stored procedure ABC
Instead, I tried this: st.setInt("a",0) and it executed perfectly.
Repro code
//Connection connection, String sp_name, Map<String, Object>params input to the method
DatabaseMetaData dbMetaData = connection.getMetaData();
HashMap<String, Integer> paramInfo = new HashMap<String, Integer>();
if (dbMetaData != null)
{
ResultSet rs = dbMetaData.getProcedureColumns (null, null, sp_name.toUpperCase(), "%");
while (rs.next())
paramInfo.put(rs.getString(4), rs.getInt(6));
rs.close();
}
String call = "{ call " + sp_name + " ( ";
for (int i = 0; i < paramInfo.size(); i ++)
call += "?,";
if (paramInfo.size() > 0)
call = call.substring(0, call.length() - 1);
call += " ) }";
CallableStatement st = connection.prepareCall (call);
for (String paramName: paramInfo.keySet()){
int paramType = paramInfo.get(paramName);
System.out.println("paramName="+paramName);
System.out.println("paramTYpe="+paramType);
Object paramVal = params.get(paramName);
st.setInt(paramName, Integer.parseInt(((String)paramVal))); //All stored proc parameters are of type int
}
Driver version or jar name
mssql-jdbc verion 6.2.1.jre8
SQL Server version
Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) - 13.0.1742.0 (X64) Jul 5 2017 23:41:17 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows 8.1 Pro 6.3 (Build 9600: )
Client operating system
Windows 8.1
Java/JVM version
1.8
Table schema
Please tell us the table schema
Problem description
For mssql-jdbc the parameter names returned by DatabaseMetaData#getProcedureColumns do not match the names accepted by CallableStatement#setInt et. al..
Link to the problem on stackoverflow put up by me:
Expected behavior and actual behavior
I am trying to execute a stored procedure using SQL Server JDBC in a method using CallableStatement:
CallableStatement st = connection.prepareCall ("{ call ABC ( ? ) }");Let say the stored procedure name is
ABCand parameter is@a. Now DatabaseMetaData returns column name@abut settingst.setInt("@a",0)returns following error:com.microsoft.sqlserver.jdbc.SQLServerException: Parameter @a was not defined for stored procedure ABCInstead, I tried this:
st.setInt("a",0)and it executed perfectly.Repro code