oracle物理连接关闭时是否会影响性能

时间:2019-05-15 17:14:50

标签: spring oracle spring-boot jdbc connection

我正在为我的最后一年的项目开发一个应用程序,我需要对Java JDBC进行快速说明。我正在使用Oracle物理连接(无连接池)。当用户按照搜索条件进行搜索时,查询执行将在10毫秒内发生,并且将结果集返回到UI最多需要1分钟。代码已附加。

Connection con=null;
        OracleConnection ocon = null;
        ResultSet rs = null;
        Gson gson = new Gson();
        String gsonOrdrHeaderEntity="";
        JSONObject searchObject = new JSONObject();
        JSONObject returnSearchObject = new JSONObject();
        CallableStatement callableStatement = null;  
        ArrayList<SearchEntity> searchArrayList = new ArrayList<>();

        try{
            con= DatasourceConfiguration.openConnection();
            ocon = (OracleConnection)con.unwrap(OracleConnection.class);

            callableStatement= con.prepareCall("call SEARCHPKG.QUERY(?,?,?,?,?)");  

            callableStatement.setString(1,entity.getSearch1());
            callableStatement.setString(2,entity.getSearch2());
            callableStatement.setString(3,entity.getSearch3());
            callableStatement.setString(4,entity.getSearch4());

            callableStatement.registerOutParameter(5, OracleTypes.CURSOR);

            callableStatement.execute();

             rs = ((OracleCallableStatement) callableStatement).getCursor(39);

            if(rs != null)
             while(rs.next()) {
                 OrderHeaderEntity searchEntity = new OrderHeaderEntity();
                                 searchEntity.setSearch1(rs.getString(1));
                                 searchEntity.setSearch2(rs.getString(3));
                                 searchEntity.setSearch3(rs.getString(4));
                                 searchEntity.setSearch4(rs.getString(5));

                                 /**
                                  * Description : Since there are will multiple order in a single search, we are adding the row to an array and iterating over it
                                  */
                                 searchArrayList.add(searchEntity);
             }


        }catch(SQLException e){
            logger.info("SQLException while performing search: "+e.getMessage());
            throw e;
        }catch(Exception e){
            logger.info("Exception while performing search: "+e.getMessage());
        }finally {
            try {
                if(rs != null) {rs.close();}
            } catch (Exception e2) {
                logger.info("Error while closing the search resultSet : "+e2.getMessage());
            }

            try {
                if(callableStatement!=null) {callableStatement.close();}
            } catch (Exception e2) {
                logger.info("Error while closing the search callableStatment :"+e2.getMessage());
            }
            finally {
        }
                try {
                    if(con!=null) {con.close();}
                } catch (Exception e2) {
                    logger.info("Error while the search connection :"+e2.getMessage());
                }


            }

        }
        /**
         * @Description : mapping result set with JAVA object
         */

        logger.info("Inside ProcedureCall >> search Proc>> converted to JSON successfully");

          gsonOrdrHeaderEntity= gson.toJson(searchArrayList); 

          searchObject.put("order_header", gsonOrdrHeaderEntity);

          returnSearchObject.put("status", "success");
          returnSearchObject.put("message","Order Header Retrieved Successfully");
          returnSearchObject.put("data", searchObject);




        return returnSearchObject.toString();

0 个答案:

没有答案