jdbc resultSet性能缓慢

时间:2012-07-18 10:10:40

标签: jdbc oracle10g

HIII,      我在我的Web应用程序中调用java类中的存储过程,有一些报告需要花费很多时间来呈现jsp / HTML,我还使用存储过程查询,它在oracle浏览器中只执行2秒钟。我检查了我的SP调用代码,我发现我的结果集获取时间非常少,但是当尝试使用While(rst.next)迭代结果集时,几乎需要3分钟才能在while循环中打印SOP,我怀疑ret.next()一定有问题, 我的代码如下,

Connection connection   = null;
CallableStatement stmt  = null;
ResultSet rst           = null ;


connection = DBConnector.getConnection();

stmt = connection.prepareCall("{call MIS_GSGR_ASON.MIS_DIVNETSALE_ASON(?,?,?,?,?,?,?,?,?)}");


            stmt.setString(1,START_DT);                 
            stmt.setString(2,END_DT);                   
            stmt.setString(3,DIVISION);             
            stmt.setString(4,LOC_ID);   
            stmt.setInt(5,USER_GRP);
            stmt.setInt(6,FIELD_ID);
            stmt.setInt(7,Integer.parseInt(PERIOD_ID));
            stmt.setString(8,zone);
            stmt.registerOutParameter(9+INC,OracleTypes.CURSOR);
            stmt.execute();
            rst = (ResultSet) stmt.getObject(9+INC);

            System.out.println("Got resultset . . . .");

            data = new ArrayList<MainActionAll>();


            while(rst.next()){
            System.out.println("In loop");} 

任何帮助都会受到高度关注,请帮帮我 谢谢,amol

1 个答案:

答案 0 :(得分:0)

也许您通过慢速网络运行查询,如果返回的行数很多,那么它的工作速度很慢?

添加一些时间检查而不是打印到控制台只是计算记录:

...
...
...
stmt.registerOutParameter(9+INC,OracleTypes.CURSOR);
long t0, t1, t2, t3, t4, t5;
t0 = System.currentTimeMillis();
stmt.execute();
t1 = System.currentTimeMillis();
rst = (ResultSet) stmt.getObject(9+INC);
t2 = System.currentTimeMillis();
System.out.println("Got resultset . . . .");
data = new ArrayList<MainActionAll>();
t3 = System.currentTimeMillis();
t4 = t3;
t5 = t3;

int rec_cnt = 0;
if (rst.next())
    {
    ++rec_cnt;
    t4 = System.currentTimeMillis();
    while (rst.next())
        ++rec_cnt;
    t5 = System.currentTimeMillis();
    }
System.out.println("execute: " + (t1 - t0));
System.out.println("stmt.getObject: " + (t2 - t1));
System.out.println("Array: " + (t3 - t2));
System.out.println("1st next: " + (t4 - t3));
System.out.println("loop: " + (t5 - t4));
System.out.println("rec cnt: " + (rec_cnt));

尝试尽可能在数据库服务器附近执行它以减少网络传输(首选localhost)。用这些时间编辑你的问题。