首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 数据库blob类型文件写入本地影片问题 [已结贴,结贴人:denmarka]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-22 13:55:49 楼主
    Connection   con   =   null;
    PreparedStatement   pstmt   =   null;
    ResultSet   rst   =   null;
    int   i   =   0;
    String   sql   =   "select   *   from   person ";
    InputStream   is   =   null;
    OutputStream   os   =   null;
    try   {

    long   beginTime   =   System.currentTimeMillis();
    Class.forName( "oracle.jdbc.driver.OracleDriver ");
    con   =   DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:aolei ",   "aolei ",   "aolei ");
    pstmt   =   con.prepareStatement(sql);
    rst   =   pstmt.executeQuery();
    while   (rst.next())   {
    BLOB   blob   =   (BLOB)   rst.getBlob(4);
    is   =   blob.getBinaryStream();
    File   file   =   new   File( "d:/out/output "+i+ ".txt ");

    try   {
    os   =   new   FileOutputStream(file);
    }   catch   (FileNotFoundException   e2)   {
    //   TODO   Auto-generated   catch   block
    e2.printStackTrace();
    }
    byte[]   b   =   new   byte[1024];
    int   len   =   0;
    try   {
    while   ((len   =   is.read(b))   !=   -1)   {
    os.write(b,   0,   len);
    }
    }   catch   (IOException   e)   {
    //   TODO   Auto-generated   catch   block
    e.printStackTrace();
    }

    try   {
    os.flush();
    is.close();
    }   catch   (Exception   e)   {
    //   TODO:   handle   exception
    }

    i++;
    }
    //   System.out.println( "length "+a);
    System.out.println( "记录数 "   +   i   +   "个 ");
    long   endTime   =   System.currentTimeMillis();
    float   sumTime   =   (float)   (endTime   -   beginTime)   /   1000;
    System.out.println(sumTime   +   "秒 ");
    }   catch   (ClassNotFoundException   e)   {
    e.printStackTrace();
    System.out.println( "没找到驱动类 ");
    }   catch   (SQLException   e)   {
    e.printStackTrace();
    }   finally   {
    try   {
    if   (rst   !=   null)   {
    rst.close();
    }
    if   (pstmt   !=   null)   {
    pstmt.close();
    }
    if   (con   !=   null)   {
    con.close();
    }
    if   (is   !=   null)   {
    is.close();
    }
    if   (os   !=   null)   {
    os.close();
    }
    }   catch   (SQLException   s)   {
    s.printStackTrace();
    }
    }


    请问byte[]   b   =   new   byte[1024];
    int   len   =   0;
    try   {
    while   ((len   =   is.read(b))   !=   -1)   {
    os.write(b,   0,   len);
    }
    }
              b的范围,是越大存入影片速度越快吗
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-22 14:01:561楼 得分:0
    我以前试过,并不是越大速度越快!
      只要够用就OK了.一定程度了,是没有什么性能上提升了.
        个人感觉
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-22 14:08:392楼 得分:0
    哦,谢谢,那最大范围是多大呢?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-23 05:26:353楼 得分:20
    引用 2 楼 denmarka 的回复:
    哦,谢谢,那最大范围是多大呢?

    这个得看你的文件的大小
    因为 b 占用的内存 文件占用硬盘空间
    如果 b太大 就会导致内存不足速度反而慢.
    如果太小  分割的次数就会太多.也不合理.

    所以要根据你的 文件和内存 来选择一个合适的值.
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved