主文件:
public class OnlyTest {
public static void main(String[] args) throws Exception {
Configuration cfg = new Configuration().addClass(TestHBM.class);
SchemaExport pTemp = new SchemaExport(cfg);
pTemp.create(true, true);
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
try {
TestHBM message = new TestHBM();
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
message.setName(String.valueOf(i));
message.setId(String.valueOf(i));
s.save(message);
s.flush();
s.evict(message);
}
long end = System.currentTimeMillis();
System.out.println(end-start);
} finally {
s.close();
}
}
}
我的机子插入10000条记录2秒中,高效吧,而且内存内有增加。
^_^,体会到了吧,离开SQL吧。
今天还有其他事,就道这儿,现在22:43。
工程下载:下载
与估计一样时间,^_^。
博客展示了一个Java程序,通过Hibernate框架向数据库插入10000条记录,在作者机子上仅耗时2秒且内存无增加,体现出高效性,还倡导离开SQL。
2万+

被折叠的 条评论
为什么被折叠?



