0

我正在使用以下代码连接到一个 Oracle 存储过程,平均为jdbcExecutionTime860 毫秒,执行加序列化时间为 172 毫秒。

jdbcExecutionTime很担心,我知道它可以做得更快,但从我所读到CallableStatement的应该是最快的。

这里有任何提高性能的提示吗?

另外:我正在使用Oracle 11with ojdbc14.jar

final long jdbcStartTime1 = System.currentTimeMillis(); 
    final long jdbcEndTime1;
    final long jdbcEndTime2;
    Connection con = null;

    logger.info("Loading properties...SYS TIME:"+System.currentTimeMillis());

    InputStream inputStream = blah.class.getClassLoader().getResourceAsStream("properties/jdbc.properties");
    logger.info("Done loading properties...SYS TIME:"+System.currentTimeMillis());
    try {

        PROPERTIES.load(inputStream); //Load the jdbc properties
        Class.forName(PROPERTIES.getProperty("jdbc.driverClassName")).newInstance(); //Load the oracle driver
        //Set the connection 
        logger.info("Starting JDBC connection...SYS TIME:"+System.currentTimeMillis());
        con = DriverManager.getConnection(PROPERTIES.getProperty("jdbc.url"), PROPERTIES.getProperty("jdbc.username"), PROPERTIES.getProperty("jdbc.password"));
        ((OracleConnection)con).setDefaultRowPrefetch(80);

        logger.info("JDBC connection established...SYS TIME:"+System.currentTimeMillis());

        String jobquery =   "{call PKG_TEST.MY_PACKAGE(?,?,?,?,?,?)}";  
        CallableStatement callStmt = con.prepareCall(jobquery);

        callStmt.setString(1,blah);                     
        callStmt.setBoolean(2, blah2);
        callStmt.registerOutParameter(3, OracleTypes.CURSOR);   
        callStmt.registerOutParameter(4, OracleTypes.CURSOR);   
        callStmt.registerOutParameter(5, OracleTypes.CURSOR);   
        callStmt.registerOutParameter(6, OracleTypes.CURSOR);   

        jdbcEndTime1 = System.currentTimeMillis();

        logger.info("Executing stored procedure...SYS TIME:"+System.currentTimeMillis());
        callStmt.execute();
        logger.info("Stored procedure complete...SYS TIME:"+System.currentTimeMillis());

        logger.info("Storing db cursor objects as result sets...SYS TIME:"+System.currentTimeMillis());
        ResultSet cur1 = (ResultSet)callStmt.getObject(3);
        ResultSet cur2 = (ResultSet)callStmt.getObject(4);
        ResultSet cur3 = (ResultSet)callStmt.getObject(5);
        ResultSet cur4 = (ResultSet)callStmt.getObject(6);
        logger.info("Completed storing cursors...SYS TIME:"+System.currentTimeMillis());

        jdbcEndTime2 = System.currentTimeMillis();

        final long jdbcExecutionTime =  (jdbcEndTime1-jdbcStartTime1);
        final long spEx_ResultSetTime = (jdbcEndTime2-jdbcEndTime1);
4

1 回答 1

1

第一次执行此操作时,大部分时间将花费在加载库(仅在您第一次使用它时发生)和创建连接上。一旦你有一个现有的连接,你应该期望大约 <10 毫秒的延迟(比你正在做的要长)

于 2012-07-05T20:16:24.643 回答