Spring引导restful web服务,多个请求,jdbc

时间:2017-07-31 06:00:37

标签: java web-services rest spring-boot jdbc

我已经编写了spring boot restful web service。我有一个控制器,它使用JDBC连接到oracle数据库并只选择一个表,我有一个客户端,它可以并行地向该控制器发送多个请求,但JDBC不能handle和resultSet confuse.return数据不完整

@Autowired
private SidebarBiz sidebarBiz;

@RequestMapping(value = "/get-equptype", method = RequestMethod.GET, headers = "Accept=application/json")
public ResponseEntity<?> getEqupTypeList() {
    try {
        List<String> equpTypeList = sidebarBiz.getEqupTypeList();
        return new ResponseEntity<Object>(equpTypeList, HttpStatus.OK);
    } catch (Exception e) {
        String errorMessage;
        errorMessage = e + " <== error";
        return new ResponseEntity<>(errorMessage, HttpStatus.BAD_REQUEST);
    }
}

public List<String> getEqupTypeList() {
    List<String> equpTypeList = new ArrayList<String>();
    if (connect()) {
        try {
            pstmt = connection.prepareStatement(SidebarQueryLookup.equipmentTypeListQuery);
            rs = pstmt.executeQuery();
            if (rs.isBeforeFirst()) {
                try {
                        while (rs.next()) {
                            equpTypeList.add(rs.getString("blah blah"));
                        }

                } catch (Exception ex) {
                    g_logger.warning(getStackTrace(ex));
                }
            } else {
                g_logger.info("Records Fetched but there is no new Records. we will try next interval  ... ");
            }
        } catch (SQLException e) {
            g_logger.warning(getStackTrace(e));
        } catch (Exception e) {
            g_logger.warning(getStackTrace(e));
        } finally {
            try {
                if (rs != null) rs.close();
                pstmt.close();
            } catch (SQLException e) {
                g_logger.warning(getStackTrace(e));
            }
        }
        disconnectFromDB();
    } else {
        throw new RuntimeException("Connection Failed !");
    }
    return equpTypeList;
}

0 个答案:

没有答案