通过前几篇文章,介绍了JadePool的许多长处,JadePool到底如何,需要经得起实践的检验。以下是插入10万条记录的测试情况。
硬件:笔记本联想G450
CPU:Intel Pentium T4300(2.1GHz)
内存:2G
IDE:NetBeans 7.2.1
数据库:SQL Server 2000
表:
create table test_xueshng(
id bigint primary key,
name varchar(16),
sex varchar(2),
birthday datetime,
address varchar(80)
);
JDBC驱动程序:sqljdbc4.jar
以下是插入10万条记录的运行结果:
/*
run:
测试时间:2013-03-19 05:05:07
插入记录数:100000 ;用时:28609毫秒。
成功构建 (总时间: 28 秒)
*/
/*
* ProcessVO测试
*/
package cn.test;
import cn.jadepool.sql.Jade;
import cn.jadepool.sql.ProcessVO;
import cn.jadepool.util.DateTool;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author hkm
*/
public class ProcessVO_InsertTest {
public static void main(String[] args) throws SQLException {
ProcessVO_InsertTest test = new ProcessVO_InsertTest();
test.insert();
/*
run:
测试时间:2013-03-19 05:05:07
插入记录数:100000 ;用时:28609毫秒。
成功构建 (总时间: 28 秒)
*/
}
/**
* 插入10万条记录测试
*/
public long insert() throws SQLException {
/*
* create table test_xueshng(
* id bigint primary key,
* name varchar(16),
* sex varchar(2),
* birthday datetime,
* address varchar(80)
* );
*/
DateTool dt = new DateTool();
long t0 = System.currentTimeMillis();
System.out.println("测试时间:" + dt.dateTime());
int length = 100000;
List v = new ArrayList();
for (int i = 0; i < length; i++) {
int k = i % 2;
String sex = "男";
if (k == 0) {
sex = "男";
}
if (k == 1) {
sex = "女";
}
String s = "" + (length * 10 + i);
s = s.substring(1);
Map m = new HashMap();
m.put("id", i);
m.put("name", ("name" + s));
m.put("sex", sex);
m.put("age", 16);//无效字段将被自动过滤
m.put("memo", "备注");//无效字段将被自动过滤
m.put("birthday", dt.dateTime(-12 * 365));//12年前出生
v.add(m);
}
ProcessVO pvo = new ProcessVO(getCon());
try {
pvo.setAutoCommit(false);
pvo.delete("delete from test_xueshng");
pvo.insert("test_xueshng", v);
pvo.commit();
} catch (SQLException ex) {
ex.printStackTrace();
pvo.rollback();
} finally {
pvo.closeCon();
}
//以下是使用Jade时的等效代码
/*
Jade j = new Jade(getCon());
j.delete("delete from test_xueshng");
j.insert("test_xueshng", v);
j.commit();
*/
long t1 = System.currentTimeMillis();
long t = t1 - t0;
System.out.println("插入记录数:" + v.size() + " ;用时:" + t + "毫秒。");
return t;
}
/**
* sqljdbc4.jar
*/
public static synchronized Connection getCon() {
Connection con = null;
String url = "jdbc:sqlserver://127.0.0.1\\dba:1436;databaseName=jadepool_test";
String userName = "jadepool_test";
String password = "123";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(url, userName, password);
} catch (SQLException ex1) {
ex1.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return con;
}
}
在此,我们可以对比以下Hibernate的情况,JadePool的性能还是相当出色的。
以下来自
Hibernate入门:批量插入数据 http://blog.youkuaiyun.com/xiazdong/article/details/7709068
Hibernate 与 原生 Jdbc 批量插入时的差距 http://liu-anxin.iteye.com/blog/1026777
Hibernate批量插入的测试 http://www.360doc.com/content/10/0910/09/1542811_52551961.shtml