我们正在使用jdbc通过pgpool连接到postgresql 9.3数据库。 当我们尝试读取java中从DB发送的数据时,有时会正确读取数据,有时我们会得到此异常。
org.springframework.jdbc.UncategorizedSQLException:
CallableStatementCallback;
uncategorized SQLException for SQL [{call schema.function_name(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}];
SQL state [34000]; error code [0]; ERROR: cursor "<unnamed portal 1>" does not exist; nested exception is org.postgresql.util.PSQLException: ERROR: cursor "<unnamed portal 1>" does not exist
我们在DAO课程中使用此代码:
Map<String , Object> outMap = BaseDAO.executeStoredProcedureSpring(
jdbcTemplate,
"schema.function_name",
ProcParams.paramIN(param_1,Types.NUMERIC),
ProcParams.paramCursor(new Map_HistoryVO()),
ProcParams.paramOUT(Types.NUMERIC),
ProcParams.paramOUT(Types.VARCHAR));
函数executeStoredProcedureSpring
try
{
connection = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
SimpleJdbcCall procedure = new SimpleJdbcCall(jdbcTemplate);
procedure.withProcedureName(procName);
procedure.withoutProcedureColumnMetaDataAccess();
for(int i = 0;i < paramarr.length; i++)
{
int position = i + 1;
String paramName = "param_" + position;
ProcParams procparam = paramarr[i];
SqlParameter sqlParameter = null;
if(procparam.getParamType().equalsIgnoreCase("IN"))
{
sqlParameter = new SqlParameter(paramName , procparam.getType());
inParams.put(paramName, procparam.getValue());
}
parameters.add(sqlParameter);
}
procedure.declareParameters((SqlParameter[]) parameters.toArray(new SqlParameter[0]));
outParams = procedure.execute(inParams);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
DataSourceUtils.releaseConnection(connection, jdbcTemplate.getDataSource());
}
pgpool的版本如下:
bash-4.1$
-bash-4.1$ ll pgpool
-rwxr-xr-x. 1 enterprisedb enterprisedb 1358832 Nov 5 2013 pgpool
-bash-4.1$ ./pgpool --version
pgpool-II version 3.3.1 (tokakiboshi)
-bash-4.1$
但是当我们删除pgpool并直接访问数据库时,我们能够正确读取数据。
请建议解决此问题。