gpt4 book ai didi

java - JDBC SQLServerException 参数未定义

转载 作者:行者123 更新时间:2023-11-30 02:39:07 25 4
gpt4 key购买 nike

我有一个 Play 2.4.3 应用程序并使用 JDBC 连接到 SQL Server DB。我刚刚编写了一个数据库类来处理调用存储过程。然而,我碰壁了:

我的过程的开始:

ALTER PROCEDURE [WebApp].[Content_GetByAppID]
(
@inAppID int,
@inContentGroupID int = null,
@inContentTypeID int = null,
@inContentStatus char(1) = 'A'
)
AS

这是我编写的准备语句的类方法:

private CallableStatement createStatement(Connection inConnection, String inProc, DataMap inParams) throws SQLException{
CallableStatement statement = inConnection.prepareCall("{call" + inProc + "}");

if( inParams != null ) {
for(Map.Entry<String,Object> e : inParams.entrySet()){
String name = e.getKey();
Object value = e.getValue();

if( value != null ){
if (value instanceof Timestamp){
// Sql does its own time conversion. Let's avoid that
statement.setTimestamp(name, (Timestamp)value, Calendar.getInstance(TimeZone.getTimeZone("GMT")) );
} else {
statement.setObject(name, value);
}
} else {
// Pass in Special SQL NUll type if parameter is null
statement.setNull(name, Types.NULL);
}
}
}
return statement;
}

我用这个来打电话: DataMap 参数 = new DataMap();

    params.put("inAppID", Play.application().configuration().getInt("richfoods.app.id"));
params.put("inContentTypeID", typeID);
params.put("inContentGroupID", groupID);
params.put("inContentStatus", status);

List<Content> content = mgContentDB.getList(
"WebApp.Content_GetByAppID(?,?,?,?)",
params);

每当 createStatement 中的语句变量尝试设置参数时,我都会收到此错误:

com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Parameter inContentTypeID was not defined for stored procedure .

有什么想法导致这个吗?

编辑:我认为值得注意的有趣的事情是错误不包含过程名称。应该不应该吧?这告诉我它找不到过程?

最佳答案

您缺少空白字符:

// Your code
inConnection.prepareCall("{call" + inProc + "}");

// Fix
inConnection.prepareCall("{call " + inProc + " }");

关于java - JDBC SQLServerException 参数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com