Java第九次作业

《Java技术》第XX次作业

(一)学习总结

1.用思维导图对本周的学习内容进行总结。

参考资料: XMind。

1079998-20170525210728325-695474689.gif

2.通过实验内容中的具体实例说明在执行executeUpdate()方法和executeQuery()方法中使用动态参数时,为什么要使用PreparedStatement接口而不使用Statement,比较使用两种接口的不同之处。

代码:

import java.io.*;
public class test01 {
    public static void main(String args[]) {
        FileInputStream in = null;
        FileOutputStream out = null;
        File fSource = new File("e:" + File.separator + "PowerDesigner"+ File.separator + "2.png");
        File fDest = new File("e:" + File.separator + "PowerDesigner" + File.separator
    + "1.png");
        if (!fSource.exists()) {
            System.out.println("源文件不存在");
            System.exit(1);
        }
        if (!fDest.getParentFile().exists()) {
            fDest.getParentFile().mkdirs();
        }
        try {
            in = new FileInputStream(fSource);
            out = new FileOutputStream(fDest);
            byte[] b = new byte[1024];
            int len = 0;
            long begintime = System.currentTimeMillis();
            while ((len = in.read(b)) != -1) {
                out.write(b,0,len);
        }
       long endtime = System.currentTimeMillis();
        System.out.println("文件拷贝完成,耗时" + (endtime - begintime) + "毫秒");
        } catch (Exception e) {
            System.out.println("文件操作失败");
        } finally {
        try {
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

}

执行结果:

使用Statement文件拷贝,是一个字节一个字节的拷贝,耗时1430毫秒;

使用PreparedStatement文件拷贝,先将内容拷贝到缓冲流中,耗时31毫秒

(二)实验总结

  • 程序设计思路:根据老师给出的程序范例,更改上次作业中相应的部分,包括数据库

  • 实验问题分析:

    问题:数据库连接不上

    原因:数据库要打开并“登录”才能连接上

    解决方案:打开数据库,连接到服务器

(三)代码托管

  • 码云commit历史截图
    1079998-20170525174111122-626609229.png

转载于:https://www.cnblogs.com/fashion999/p/6905241.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值