免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2042 | 回复: 0

[求助] oracle中function执行效率问题 [复制链接]

论坛徽章:
0
发表于 2015-04-28 15:19 |显示全部楼层
public class GPtest {

        public static void main(String[] args) {
               
                FileOutputStream fos = null;
                BufferedWriter bw = null;
               
                Connection conn = null;
                Statement stmt = null;
                ResultSet rs = null;
               
                int i;
               
                try{
                        fos = new FileOutputStream("test_data.txt");
                        bw = new BufferedWriter(new OutputStreamWriter(fos));
                       
                        Class.forName("org.postgresql.Driver");
                        conn = DriverManager.getConnection("jdbc:postgresql://72.160.0.4/Test", "gpadmin", "gpadmin");
                        stmt = conn.createStatement();
                        rs = stmt.executeQuery("select * from t_test");
                       
                        int columnNum = rs.getMetaData().getColumnCount();//表的字段数
                       
                        while(rs.next()){
                                for(i=1;i<=columnNum;i++){
                                        bw.write(rs.getObject(i)+" ");
                                }
                                bw.write("\n");//写完一条记录后换行
                        }
                       
                        bw.flush();
                }catch(Exception e){
                        e.printStackTrace();
                }finally{
                        try{
                                if(rs!=null){
                                        rs.close();
                                }
                                if(stmt!=null){
                                        stmt.close();
                                }
                                if(conn!=null){
                                        conn.close();
                                }
                        }catch(Exception e){
                                e.printStackTrace();
                        }
                       
                        try{
                                if(fos!=null){
                                        fos.close();
                                }
                                if(bw!=null){
                                        bw.close();
                                }
                        }catch(Exception e){
                                e.printStackTrace();
                        }
                }
               
        }

}

以上是我写的一个java程序,在eclipse里执行时间平均是4.5s,
但是如果我把以上程序写入到oracle的java source中,并且调用以这个java source生成的function,执行效率就非常慢,大概是6到7分钟。

后来把BufferedWriter bw 的write过程去掉(即只执行查询),时间是13s,
就是说该程序在oracle中执行的时候,绝大部分时间是在执行write。

请问各位大神有没有提高效率的方法?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP