简体   繁体   English

Java SQL存储过程ResultSet无法从仅包含1行的结果中获取数据

[英]Java SQL stored procedure ResultSet can't get data from results that only contain 1 row

I can execute the stored procedure fine and collect the results when there is more than 1 row returned. 我可以很好地执行存储过程,并在返回多于1行时收集结果。 However when the procedure returns 1-row ResultSet.next() always returns false so I can't get that data. 但是,当过程返回1行时,ResultSet.next()始终返回false,因此无法获取该数据。 Any ideas as to why this happens? 有什么想法为什么会这样?

Here is my code: 这是我的代码:

List<Panel> panels = new ArrayList<>();
    try {
        String SPsql = "EXEC [dbo].[CR_Pick_Trim_Route] ?";
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://database", "username", "password");
        CallableStatement ps = conn.prepareCall(SPsql);
        ps.setEscapeProcessing(true);
        ps.setQueryTimeout(300);
        ps.setString(1, route);

        boolean hadResults = ps.execute();

        while (hadResults)
        {
            ResultSet reset = ps.getResultSet();

            while (reset.next()) {
                String route_name = reset.getString("route_name");
                String order_no = reset.getString("order_no");
                String product = reset.getString("pick_comp");
                String drop_no = reset.getString("drop_no");
                String desc = reset.getString("long_description");
                String analysisA = reset.getString("analysis_a");
                String consumer = reset.getString("comp_cons");
                String warehouse = reset.getString("pick_wh");
                String key = reset.getString("Key");
                int total = reset.getInt("pick_qty");
                String scanned = reset.getString("Scanned");
                String picked = reset.getString("picked");
                String original = reset.getString("original");

                Panel p = new Panel(route_name, order_no, drop_no, product, desc, analysisA, consumer, warehouse, (!picked.equals("No")), key, total, (scanned.contains("Y")), original);
                panels.add(p);
            }
            hadResults = ps.getMoreResults();
        }

Found someone has asked similar question in the below link : 在下面的链接中发现有人提出了类似的问题:

why executeUpdate() method returns -1 with callable statement instead of update count or 0? 为什么executeUpdate()方法返回带有可调用语句的-1而不是更新计数或0?

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM