java 的smallfile类库_sql2o: sql2o 是一个 Java 类库,可让你执行 SQL 查询并解析结果到 POJO 中,只需少数几行代码...

sql2o sql2o.svg?branch=mastersql2o.svgbadge.svg?branch=master

Sql2o is a small java library, with the purpose of making database interaction easy.

When fetching data from the database, the ResultSet will automatically be filled into your POJO objects.

Kind of like an ORM, but without the SQL generation capabilities.

Sql2o requires at Java 7 or 8 to run. Java versions past 8 may work, but is currently not supported.

Examples

Check out the sql2o website for examples.

Performance

A key feature of sql2o is performance. The following metrics were based off the

Dapper.NET metrics.

Note that typical usage can differ from optimal usage for many frameworks. Depending on the framework,

typical usage may not involve writing any SQL, or it may map underscore case to camel case, etc.

Performance of SELECT

Execute 1000 SELECT statements against a DB and map the data returned to a POJO.

Code is available here.

Method

Duration

Hand coded ResultSet

60ms

Sql2o

75ms (25% slower)

98ms (63% slower)

197ms (228% slower)

293ms (388% slower)

447ms (645% slower)

494ms (723% slower)

636ms (960% slower)

Contributing

Want to contribute? Awesome! Here's how to set up.

Coding guidelines.

When hacking sql2o, please follow these coding guidelines.

Note on running Oracle specific tests

In order to run the Oracle database tests you will have to add the Oracle Maven repo to your settings.xml as instructed in the Oracle Fusion Middleware Maven Setup guide

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java处理大文件时,我们要考虑以下几个问题: 1. 内存问题:如果一次性读取整个文件到内存,当文件非常大时,可能会导致内存溢出。因此,我们要采用分块读取的方式,分批处理文件。 2. 效率问题:读取大文件时,效率非常重要。使用BufferedReader和BufferedWriter可以提高效率,因为它们会使用缓冲区进行读写操作,减少了频繁的I/O操作。 3. 处理异常问题:由于大文件的处理要较长时间,因此可能会出现各种异常情况,例如硬盘空间不足、文件被占用等。这些异常要进行处理,否则会影响程序的稳定性。 下面是一个简单的Java程序,用于读取大文件并将其拆分成多个小文件: ```java import java.io.*; public class FileSplitter { public static void main(String[] args) { try { // 设置每个小文件的大小为100MB int bufferSize = 1024 * 1024 * 100; // 打开大文件 FileInputStream fis = new FileInputStream("bigfile.txt"); BufferedInputStream bis = new BufferedInputStream(fis); byte[] buffer = new byte[bufferSize]; int count = 0; // 逐块读取大文件,并写入小文件 while (bis.read(buffer) != -1) { FileOutputStream fos = new FileOutputStream("smallfile_" + count + ".txt"); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(buffer); bos.flush(); bos.close(); count ++; } bis.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } } ``` 这个程序将大文件分割成多个小文件,每个小文件的大小为100MB。如果要更细粒度的控制,可以根据要自行修改代码。同时,要注意在处理大文件时,要耐心等待程序执行完毕,不要过早断程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值