Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SimpleJDBCall仅返回1行_Java_Postgresql_Stored Procedures_Plpgsql_Spring Jdbc - Fatal编程技术网

Java SimpleJDBCall仅返回1行

Java SimpleJDBCall仅返回1行,java,postgresql,stored-procedures,plpgsql,spring-jdbc,Java,Postgresql,Stored Procedures,Plpgsql,Spring Jdbc,我已经用pl/pgsql编写了一个存储过程,它在pgAdmin中运行良好。我使用simplejbdcall调用返回一组记录的过程。当我使用SimpleJDBCall execute函数从java调用存储过程时,只有一行返回给java,在pgAdmin中调用该过程时返回多行 我的存储过程是: CREATE OR REPLACE FUNCTION get_instruments_list(userName varchar, OUT a int,out b int,out c int)

我已经用pl/pgsql编写了一个存储过程,它在pgAdmin中运行良好。我使用simplejbdcall调用返回一组记录的过程。当我使用SimpleJDBCall execute函数从java调用存储过程时,只有一行返回给java,在pgAdmin中调用该过程时返回多行

我的存储过程是:

    CREATE OR REPLACE FUNCTION get_instruments_list(userName varchar, OUT a int,out b int,out c int)
    RETURNS setof Record 
    AS
    $$
    DECLARE
       BEGIN
           RETURN query select 1,2,3;
           RETURN QUERY select 5,2,3;
           RETURN query select 6,2,3;
           return;
       END;
    $$
   LANGUAGE 'plpgsql' VOLATILE;
我调用存储过程的java函数是:

    public static void main(String[] a){

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/config/applicationContext-postgreSQL.xml");
    JdbcTemplate jdbcTemplate = (JdbcTemplate) applicationContext.getBean("pgJdbcTemplate");
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate);

    jdbcCall.setSchemaName("dhapic");
    jdbcCall.setProcedureName("get_instruments_list");
    Map<String, String> inputParamater = new HashMap<>();
    inputParamater.put("userName", "dhanush");
    jdbcCall.returningResultSet("result", new RowMapper() {
        @Override
        public InstrumentList mapRow(ResultSet rs, int rowNum) throws SQLException {
            InstrumentList instrumentList = new InstrumentList();
            instrumentList.setInstrumentId(rs.getInt(1));
            instrumentList.setInstrumentToken(rs.getInt(2)+"");
            instrumentList.setUserRole(rs.getInt(3)+"");
            return instrumentList;
        }
    });
    Map<String,Object> response = jdbcCall.execute(inputParamater);
    System.out.println("response"+response);
 }
publicstaticvoidmain(字符串[]a){
ApplicationContext ApplicationContext=new ClassPathXmlApplicationContext(“/config/ApplicationContext postgreSQL.xml”);
JdbcTemplate=(JdbcTemplate)applicationContext.getBean(“pgJdbcTemplate”);
SimpleJdbcCall jdbcCall=新SimpleJdbcCall(jdbcTemplate);
jdbcCall.setSchemaName(“dhapic”);
setProcedureName(“获取仪器列表”);
Map InputParameter=new HashMap();
InputParameter.put(“用户名”、“dhanush”);
returningResultSet(“结果”,新的行映射器(){
@凌驾
公共InstrumentList映射行(ResultSet rs,int rowNum)引发SQLException{
仪表列表仪表列表=新仪表列表();
setInstrumentId(rs.getInt(1));
setInstrumentToken(rs.getInt(2)+“”);
setUserRole(rs.getInt(3)+“”);
返回列表;
}
});
Map response=jdbcCall.execute(InputParameter);
System.out.println(“响应”+响应);
}
JdbcTemplet值是使用spring传递的

响应对象只包含1行,但我希望有3行。
请帮我调试这个问题。

如果从
psql
运行相同的SQL会发生什么?我可以在psql(PgAdmin)中运行它时获得所有行。问题是我无法获得java.OK中的所有行,Spring模板为这个查询生成的确切SQL是什么?从PostgreSQL日志或Spring日志中获取它。{调用dhapic.Get_instruments_list(?,?)}这是我从callString中获取的。这是你问的吗?好的,这是JDBC转义查询。由于它使用JDBC转义,要获取实际的SQL,您需要在
PostgreSQL.conf
中将
log\u语句设置为
all
,然后转到PostgreSQL日志。但这可能不值得,只要你真的完全确定你发送的是完全相同的参数,这就足够了。